Introduction to rendering principles of browsers (1)

Source: Internet
Author: User

When you see this title, you will surely think of this Article "How Browsers Work". This article details many browser details and translates them into Chinese. Why do I want to write another article? For two reasons,

1) This article is too long and the reading cost is too high. You cannot read it in one breath.

2) I learned a lot after reading this article, but it seems to be of little help to my work.

Therefore, I am going to write this article to solve the above two problems. I hope you can finish reading it on your way to work, or on the toilet, and learn something that can be used at work.

Browser Workflow

Let's take a look at the figure:

From the figure above, we can see several things:

1) the browser will parse three things:

  • One is HTML/SVG/XHTML. In fact, Webkit has three C ++ classes that correspond to these three types of documents. Parsing these three files generates a DOM Tree.
  • CSS. parsing CSS produces the CSS rule tree.
  • Javascript and scripts are mainly used to operate DOM Tree and CSS Rule Tree through dom api and cssom api.

2) After parsing, the browser engine constructs the Rendering Tree through the DOM Tree and CSS Rule Tree. Note:

  • The Rendering Tree is not equivalent to the DOM Tree, because something like Header or display: none does not need to be placed in the Rendering Tree.
  • The CSS Rule Tree is mainly used to complete the matching and append the CSS Rule to each Element on the Rendering Tree. That is, the DOM node. That is, the so-called Frame.
  • Then, calculate the position of each Frame, that is, each Element, which is also called the layout and reflow processes.

3) Finally, call the Native gui api to draw the image.

DOM Parsing

Parse the html dom Tree as follows:

 
 
  1.     <title>Web page parsing</title> 
  2. <body> 
  3.     <p> 
  4.         
  5.         <p>This is an example Web page.</p> 
  6.     </p> 
  7. </body> 

The above HTML will be parsed as follows:

The following is another scenario with SVG labels.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.