简体   繁体   中英

Why does DOM Manipulation take so long?

I have read in the past that manipulating the DOM is one of the most expensive things you can do in javascript. I've also seen it demonstrated in perfs . Why does it take so long?

This slowness happens due to the document reflow. From Google Developers Speeding up JavaScript: Working with the DOM guide

Working with the DOM can cause browser reflow, which is the browser's process of determining how things should be displayed. Directly manipulating the DOM, changing CSS styles of elements, and resizing the browser window can all trigger a reflow . Accessing an element's layout properties such as offsetHeight and offsetWidth can also trigger a reflow. Because each reflow takes time , the more we can minimise browser reflow, the faster our applications will be.

Every time the DOM is updated, the document is re-rendered. Layout is very complicated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM