官术网_书友最值得收藏!

How a Web Page Renders

How does a web page render in the browser? We've learned a lot about HTML and CSS in this chapter, but let's see how these technologies are put together by the browser to render our web page.

The following figure shows a flowchart of the process, which is further explained below:

Figure 1.37: Flow chart of the web page render process

To summarize the process:

  1. The user starts by navigating to a URL, possibly via a hyperlink or by typing the URL into the address bar of their browser.
  2. The browser will make a GET request to the disk or a network. It will read the raw bytes from that location and convert them to characters (based on character encoding such as UTF-8).
  3. The browser then parses these characters according to the HTML standard to find the tokens that are familiar as HTML elements, such as <html> and <body>.
  4. Another parse is then made to take these tokens and construct objects with their properties and based on the rules appropriate to that token. At this point, the objects are defined.
  5. Finally, the browser can define the relationships between these objects and construct the HTML DOM for the web page.
  6. At this point, we have a DOM but not a rendered web page. The next task is to construct the CSSOM. Again the browser will load any style sheet resources it needs to, which were found while parsing the document. It will then construct the styles associated with nodes in the tree structure, which gives us the CSSOM.
  7. With the information gathered in the DOM and the CSSOM, the browser can create a render tree. The render tree is constructed by combining information from the CSSOM and the HTML DOM. Nodes in the HTML DOM that will not be rendered (for instance, those with the display: none; style) are excluded from the render tree. Those that are rendered are enriched with their computed style rules.
  8. Now the browser has all the information it needs, it can begin to calculate the positions of elements in the rendered viewport. This is called the layout stage. The browser lays elements out based on their size and position within the browser viewport. This stage is often also called reflow. It means the browser must recalculate the positions of elements in the viewport when elements are added to or removed from the page or when the viewport size is changed.
  9. Finally, the browser will rasterize or paint each element on the page, depending on their styles, shadows, and filters to render the page the user will see.

That is a brief and simplified summary of the rendering of a web page. Think about how many resources might be loaded on a relatively complicated website and with JavaScript running events and we can see that much of this process happens frequently and not in such a linear manner. We can start to see the complexities of what a browser is doing when it renders your web page.

主站蜘蛛池模板: 通化市| 科技| 鸡西市| 叙永县| 平原县| 丹东市| 拜城县| 尤溪县| 库尔勒市| 石门县| 调兵山市| 香港| 内丘县| 平顶山市| 榆社县| 蒙山县| 巩留县| 富顺县| 高台县| 博野县| 濮阳县| 尼玛县| 乡宁县| 建平县| 哈尔滨市| 乳山市| 北海市| 定陶县| 赣州市| 德化县| 锡林浩特市| 太康县| 唐山市| 平定县| 平安县| 瑞丽市| 城口县| 当涂县| 海伦市| 海安县| 托里县|