Page rendering reflow test notes_html/css_WEB-ITnose
Page repaints (repaints) and reflow (reflow) have been introduced a lot on the Internet. I just looked at them before and didn’t understand them carefully, so I will take some notes now
Some useful links
http://www.zhangxinxu.com/wordpress/2009/10/attention-reflow-to-make-web-faster/
http://www. zhangxinxu.com/wordpress/2010/01/Reflow and redraw: Does CSS performance make JavaScript slow down? /
First of all, you need to roughly know how the browser renders the page
When the document is first loaded, the browser engine will parse the HTML document to build a DOM tree, and then based on the DOM elements Geometry properties build a tree for rendering. Each node of the rendering tree has attributes such as size and margin, similar to the box model (since hidden elements do not need to be displayed, the rendering tree does not contain hidden elements in the DOM tree). When the rendering tree is constructed, the browser can place the elements in the correct location, and then draw the page based on the style attributes of the rendering tree nodes.
Anyway, you need to know the box mode to understand redrawing and reflowing
Repaints
When some elements in the render tree need to update attributes, and these Attributes only affect the appearance and style of the element, but do not affect the layout, such as background-color. It is called redrawing
This is a sentence copied from the Internet, and it is easy to understand. It changes the appearance, does not change the layout, and does not affect other dom
Reflow )
This is the point
The term reflow refers to the process by which a web browser recalculates the position and geometry of elements in a document in order to re-render part or all of the document. Because reflow is a user-led modular operation in the browser, you know how to improve the reflow time and know various document properties (DOM node depth, CSS rendering efficiency, various The impact of style changes) on reflow time is very helpful for developers. Sometimes, even if only a single element is reflowed, its parent element and any elements that follow it may also be required to reflow
Copied from the Internet, according to my understanding, reflow is very easy to operate. , and it can easily affect performance, so we have to pay more attention and try not to cause reflow.
Then why does it affect performance?
The reflow of an element causes all its child elements and the DOM The subsequent reflow of the ancestor elements that follow.
This sentence was also copied from the Internet. My understanding is that the reflow not only affects itself, but also affects the rearrangement and calculation of other elements. (Including the calculation of styles)
Anyway, the final summary is that reflow has a great impact. You must understand it and try to minimize it from happening
What operations will cause reflow?
1. Resizing the window
2. Changing the font
3. Adding or removing a stylesheet )
4. Content changes, such as a user typing text in an input box (Content changes, such as a user typing text in an input box)
5. Activate CSS pseudo-classes, such as: hover (Activation of CSS pseudo classes such as :hover (in IE the activation of the pseudo class of a sibling))
6. Manipulating the class attribute the class attribute)
7. A script manipulating the DOM (A script manipulating the DOM)
8. Calculating offsetWidth and offsetHeight attributes (Calculating offsetWidth and offsetHeight)
9. Settings The value of the style attribute (Setting a property of the style attribute)
10. Fixed positioned elements will always reflow when dragging the scroll bar
Copied from the Internet, it is indeed possible Caused reflow
Why is it possible? Because modifying the style may only modify the background, color, etc., it may just redraw, not necessarily reflow
How should we avoid reflow (or to cause as little reflow as possible)?
1. Reduce unnecessary DOM depth. Because no matter you change any level in the DOM node tree, it will affect every level of the node tree - from the root node all the way to the modified child node. Unnecessary node depth will cause more time to be spent performing reflow.
2. Streamline css and remove useless css
3. If you want to change complex performance, such as animation effects, then please implement it outside this flow line. Use position-absolute or position-fixed to achieve it.
4. Avoid unnecessary complex CSS selectors, especially using sub-selectors, or consuming more CPU to do selector matching.
5. Since calculating offsetWidth will also cause reflow, then use a variable to save it
6. To modify multiple styles at one time, use cssText, or directly add a className
Note: Reflow will definitely cause redraw, but redraw will not necessarily cause reflow.
How to test redraw and reflow?
I saw online that there is a testing tool Speed Tracer, but it can no longer be found in the chrome web store!
Then I saw an article about how to check the page rendering address http://www.ghugo.com/chrome-rendering-tools-1/
Chrome Opera can test it like this, ff, I don’t know how to do it in Safari
It mainly allows the user to see that the page is rendered and how big the rendering area is (but it seems that it cannot distinguish between redraw and reflow)
How to operate?
1. Call up the developer management tool (f12)
2. Press the esc key
3. Select the Rendering tab
4. Check Show paint Rectangles tab
As shown in the figure
If you operate it, you will find that if an element is rendered, a green box will appear, showing the rendering The area
This can be used to test some of the reflow and rendering mentioned above
1.fixed positioning, dragging the scroll bar will keep reflowing
The test found that it is indeed rendering all the time, but fortunately it is only rendering to itself and does not affect other doms
2. Adjust the window size and zoom the browser
The test found that the entire page is being rendered, which should be a reflow that has a greater impact
3. Delete the element
before deleting it
Deleted
The test found that it will affect the elements after it, but will not affect the previous elements
4. Change the font
It will affect the rendering of itself and the elements below it
5. Trigger hover
If you just redraw, it will only affect itself (such as changing the background, font color)
If it is reflow, it will affect the reflow of the elements below it (such as changing the font, height)
6. Calculate offsetWidth and offsetHeight
This has not been tested The page is rendered -_-!
Testing reflow and redrawing is a troublesome thing. I haven’t found a tool that can distinguish redrawing and reflowing yet
But if you just want to view For page rendering, chrome’s Rendering is enough

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex
