why do people use virtual doms?

So do I understand correctly that Virtual DOM duty among other things is to abstract real DOM operations we would need to do?


Would correct/efficient HTML DOM manipulations have same effect as working with Virtual DOM in complex applications?


You’re right. A virtual DOM ultimately translates to calls to the real DOM. Therefore, the virtual DOM can only ever be slower than optimal usage of the real DOM. If you’re adding, removing, moving elements on the actual DOM in a way that actually represents what changes you’re making, it will be efficient.

Then why does Virtual DOM exist?

People invented virtual DOM to abstract away “how things are changing” and instead think about “how things are currently.” The architecture of things like React and Vue is basically that components have the code to declare the way that the DOM should currently look. Then the code in these frameworks does a big re-computation of how they think things should be, then it diffs it against how the components said things should be the last time it asked them, then it applies that diff to the real DOM.

So, virtual DOM is a way to ameliorate the inherent slowness of this design, under the belief that its benefits will outweigh the costs.


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top