The process by which the browser recalculates the positions and geometries of page elements in order to re-render part or the entire page is called reflow. Since reflow is a user-blocking operation in the browser, it is important to understand how to reduce the number of reflows and how different document attributes (DOM depth, CSS efficiency, style changes without type) affect the number of reflows. The impact is very necessary for developers. Sometimes an element in a reflow page will reflow its parent element (Annotation: plural here) and all child elements.
There are various user operations and DHTML changes that may trigger reflow. Adjusting the size of the browser window, using javascript to calculate styles ( computed styles ), creating and deleting elements in the DOM, and changing the class of elements will trigger reflow. It is worth noting that some operations will trigger reflow multiple times, beyond your imagination. The following picture is from Steve Souders' speech " Even Faster Web Sites ":
From the above table, it is obvious that not all JavaScript-controlled styles trigger reflow in all browsers, and even if they are triggered, the number of times is not the same. At the same time, it can be seen that modern browsers are getting better and better at controlling the number of reflows.
At Google, we measure the speed of our pages and web applications in a variety of ways, and reflow is a key factor we consider when adding UI. We strive to deliver a lively, interactive and delightful user experience.
in principle
Here are some principles for reducing reflow:
In the video below (Annotation: Quoted from YouTube, cannot be viewed, please go to the original text to bypass the wall), Lindsey introduces some methods to reduce reflow.
Further reading
Original translation: http://www.99css.com/2009/06/minimizing-browser-reflow.html