Why is HTML DOM slow?

Imagine a DOM which a list of 10 items on your web page and if because of any user interaction, web page just needs to update one of them, that’s not possible. In this case, the entire real DOM will be re-rendered. Just to update one item of the list of 10 items, entire list will be re-rendered.

Is the DOM slow?
Every talk and article about the Virtual DOM will point out that although today’s JavaScript engines are extremely fast, reading from and writing to the browser’s DOM is slow.

This isn’t exactly true. The DOM is fast. Adding and removing DOM nodes doesn’t take much more than setting a property on a JavaScript object. It’s a simple operation.

What is slow, however, is the layout that browsers have to do whenever the DOM changes. Every time the DOM changes, browser need to recalculate the CSS, do layout, and repaint the web page. This is what takes time.

Uday Ogra

Connect with me at http://facebook.com/tendulkarogra and lets have some healthy discussion :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *