Why is DOM manipulation so slow?

Question

Why is DOM manipulation so slow?

Answer

When there is a change to an element in the DOM, the DOM has to re-render the element and all of the element’s children to the DOM - making DOM manipulation very slow in comparison to the Virtual DOM.

1 Like

Actual DOM works on tree structure, which means if user interact with website and make any changes, it’ll update the entire DOM (tree structure), while virtual DOM is based on JavaScript object which compares present and previous versions of DOM and update only the specific nodes of the DOM, hence making it fast, optimized performance

7 Likes

One of the main causes of slow DOM manipulation is accessing the DOM too frequently or unnecessarily, as each time you use a method like document. getElementById, document. querySelector, or document. createElement, you are triggering a reflow or repaint.

1 Like

If some one is interested in chewing a long read, which is not byte sized, follow the link for a multi-part series.

2 Likes