indie-blogs-bg

Critical Rendering Path

Critical Rendering Path featured image
23 Dec 2022
Nirlep Patel

Understanding the Concept of Critical Rendering Path

There is a proper process that is followed by the browser to convert the CSS, JavaScript, and HTML into rendered pixels that are visible to the user sitting in front of the screen. And this whole process of displaying pixels is known as the Critical Rendering Path or CRP. There is a major challenge to undergo behind those fast displays of web pages on the user interface. When seeing a website loading in 1 sec, what happens besides it is that the most important piece of information reaches the user within one sec which helps in maintaining the flow in the execution of the information and thus resulting in a positive user experience. This process works on the DOM or document object model which helps the browser in creating a render tree. Once the render tree is successfully created, the layout of the page determines the location and size of everything to be placed on the screen. Once all this is done, the final rendered pixels get painted on the screen of the user.

⮚ How Does Critical Rendering Path Work?

The critical Rendering Path process is no less than any big challenge. Factors like the number of HTTP requests, the size of the file, the weight of elements present on the page, web hosting, and a lot more things directly affect the page load time. But what function does CRP perform? The critical rendering path monitors all the numerous steps that a browser performs to receive CSS, HTML, and Javascript bytes as well as all the other techniques that are essential in the process of rendering the initial view of the resulting web page. Style, Layout- painting as well as construction, constructing the object model, and compositing (in some cases) are some of the steps involved in the rendering process of the page. Several problems occur with the rendering process, and to resolve this process and make the website load all the pages at the most appropriate timings, the optimization process takes place.

⮚ Optimization of Critical Rendering Path

Optimization directly works on prioritizing the way the content is to be displayed on the screen. It includes factors like the resources that are to be displayed and loaded, reducing the file size of different resources, and controlling the serial-wise order of the content that is to be loaded on the page. If you want to optimize the rendering path, follow the given instructions:

  1. Minimize the Number of Critical Bytes

You can directly minimize the number of critical bytes in the web page by simply compressing each resource included. For further optimization, you can make use of CSS and HTML deception.

  1. Minimize the Number of Critical Resources

Try to include less critical resources on your pages as they may be the major cause for the blockage of the smooth initial rendering of a page. If there will be few critical resources available on the page, then the browser has to put less effort while displaying the pixels or the content to the user. You can minimize the critical resources by eliminating extra resources from the page, making them download non-synchronously, marking them as async, or directly eliminating or deferring their downloads.

  1. Minimize the Critical Path Length

For further optimization, one can minimize the critical path length by downloading all the critical resources available on the web page as early as possible. Critical path length in simple terms is the number of circular trips between the host of the assets and the browser. It gets initiated from the very start of the request to the response, and the retrieval.

⮚ DOM (Document Object Model)

The DOM model functions majorly with the use of 4 major steps. These steps are as follows:

  1. Converting all the bytes into the characters
  2. Converting all the HTML responses into the token
  3. Conversion of tokens into the nodes
  4. Build the final DOM tree

All the responses from the HTML turn into tokens which later turn into nodes which at last turn into forming a DOM tree. All the single DOM tags which have been used start with a startTag token and at last end up with an endTag token. Nodes consist of all the admissible information related to the HTML element. Based on the token hierarchy, nodes are now connected in the form of a DOM tree. Tokens are all the information that a node describes. We define this hierarchy as, if any node is having another node inside it, then another new set of startTag and endTag comes in between the previous endTag and startTag tokens. The more the number of nodes in a DOM tree, the longer time it will take in the critical rendering path. Note- Adding more and more extra nodes in the tree will negatively influence the performance of the same. But yes, adding a few nodes won’t make any such difference.

⮚ What is a Render Tree?

Both the DOM and the CSSOM trees are captured into the render tree. The render tree captures both- the content as well as the styles. To construct a render tree, the browser needs to check every node individually and with proper care. After every node gets checked from the very bottom (roots) of the DOM tree, the CSS rule is applied. Only visible content can be captured by the render tree. As we are well aware that the head section doesn’t contain any visible information and which is why it is not included in the render tree. If there will be no display available, then there will be nothing in the render tree itself.

⮚ Example of Critical Rendering Process

Let us assume your page has a combination of about 24-25 pictures to exhibit on the screen. Then only a few of those pictures are likely to be placed above the fold. Try focusing on those pictures first. By doing so you can increase the time of your page load time. The remaining other pictures can get deferred for later.