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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.
