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

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.

主站蜘蛛池模板: 武宁县| 科尔| 肥东县| 新泰市| 交口县| 德江县| 奎屯市| 茌平县| 宾川县| 晋中市| 漾濞| 高青县| 德阳市| 明星| 明星| 琼海市| 双牌县| 会宁县| 连江县| 如皋市| 昌平区| 浠水县| 广宁县| 项城市| 德兴市| 延川县| 神农架林区| 神农架林区| 徐州市| 太白县| 濉溪县| 金阳县| 五华县| 迭部县| 水富县| 上栗县| 襄城县| 遵义市| 崇义县| 英山县| 富锦市|