search
HomeWeb Front-endHTML TutorialPage 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

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

Explain the importance of using consistent coding style for HTML tags and attributes.Explain the importance of using consistent coding style for HTML tags and attributes.May 01, 2025 am 12:01 AM

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.