The Cssom tree and the DOM tree join together to form a render tree, which is used to calculate the layout of visible elements and as input to the process of rendering pixels to the screen.
- The DOM tree and the Cssom tree are joined together to form the render tree.
- The render tree contains only the nodes used to render the page
- The layout calculates the exact position and size of each object
- Painting is the last step, drawing requires the use of the render tree to display pixels on the screen
The first step is to combine the DOM tree and the Cssom tree to form a "render tree", which is used to describe all the visible dom content and attach Cssom style information to the node.
In order to form a rendering tree, the browser generally does things such as:
- Iterate through each visible node, starting with the DOM tree root node
- Some nodes are completely invisible (such as script tags, meta tags, etc.), and these nodes are ignored because they do not affect the rendered output
- Some nodes are hidden through CSS styles, which are also ignored-for example, the span node in the previous example is ignored in the render tree because the span style is display:none;
- For each visible node, find the appropriate matching Cssom rule, and apply the style
- Show visible nodes (nodes include content and computed styles)
Remember
- Remembering the difference between "Visibility:hidden" and "Display:none", "Visibility:hidden" sets the element to be invisible, but also occupies a certain space on the layout (for example, it will be rendered as an empty box), but " The element of Display:none "is to remove a node from the entire render tree, so it is not part of the layout.
The final output is a render that includes the style information and content information for the visible content on the screen.
We know which elements should be displayed as well as the style of the elements, but we have not yet calculated the exact position and size of the elements in the device-this is the "layout" phase, also called "Reflow".
<HTML> <Head> <Metaname= "Viewport"content= "Width=device-width,initial-scale=1"> <title>Critial Path:hello world!</title> </Head> <Body> <Divstyle= "width:50%"> <Divstyle= "width:50%">Hello world!</Div> </Div> </Body></HTML>
The above page shows two div: the first div is half the entire view, the second div is half the width of the father-that is, 25% of the entire view.
The output of the layout is the "box model", and the relative positioning is converted to absolute pixels on the screen.
Finally, we only turn all nodes on the render tree into exact pixels on the screen-this step is often referred to as "painting" or "rasterizing".
Each step takes some time, and the Google Chrome opening tool describes the time it takes for us to describe some of the steps:
- Constructs the render tree and calculates the location and size information captured in the "Layout" time on the timeline
- Once the layout is complete, the browser calculates the "Paint Setup" and "paint" events to describe when the render tree is converted to the on-screen century pixel.
Displays the time the render tree is constructed and the layout and paint are affected by the size of the page, the style applied, and the device that is running.
The larger the page, the more work the browser will do, and the more complex the style, the more time it takes to painting the stage.
However, our page is complete! Woooo!
Let's take a quick look at what the browser does:
- Working with HTML tags to build a DOM tree
- Working with CSS tags to build cssom tree
- Connect Cssom tree and Dom tree to form a render tree
- Run layouts on the render tree to calculate the shape of each node
- Draw each node on a screen
Although our page is very simple, it does a lot of work! In the next chapter we discuss how to optimize rendering.
Original: https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-tree-construction?hl=en
Render Tree Render Trees