Understanding web page rendering concepts and measuring render performance with Chrome DevTools
It doesn’t matter how good your site is; if it takes too long to download, no one will wait to see it. If your site takes more than 3 seconds to load, there is a high probability that you will lose some of your visitors. But did you know that you can dramatically improve the load time of your web app using progressive rendering? Progressive rendering not only improves loading speed, but also solves some serious problems in client-side and server-side rendering methods. To better understand progressive rendering, let’s take a look at how client-side and server-side rendering works.
Client side rendering
- When the user navigates to the web page, a request is sent to get the HTML document.
- The server sends HTML code with empty body and script tags to load JS bundles.
- The browser parses HTML and sends HTTP requests to get JS bundles. At this time, the user sees either a piece of HTML content, a blank page, or a loading indicator.
- Only after the main JS bundle is received and rendered, the user sees real, meaningful content.
In the CSR, after the JS is loaded, the content will be loaded asynchronously. We can load critical content first and then non-essential content.
Server side rendering
When rendering on the server side, the HTML is rendered on the server and sent to the client. The content that we need to display on the screen becomes available immediately after the HTML is parsed; hence, primary rendering of content is faster than CSR. Now, let’s see how SSR works:
- The browser requests HTML from the server.
- The server makes API requests and renders HTML content on its side.
- The compiled HTML is sent to the browser.
- Once the browser downloads and parses the HTML, the web application becomes available to the end user without waiting for the JS bundles to load.
- The browser downloads and runs JS bundles to make the page interactive.
Although we get fast rendering of the content, the page will not be interactive until we load and execute the JS.
We can deal with the disadvantages of CSR with SSR. But other serious flaws remain, such as rendering critical and non-critical content before sending it to the client. I know what you are thinking now. Is there an approach where we can combine both mentioned methods, right? I have good news for you! By using progressive rendering, you combine the benefits of CSR and SSR. Now let’s take a look at how we can enhance your customer experience with progressive rendering techniques.
Server-side progressive rendering
“Progressive Server-Side Rendering: The key to speeding up a web page is the method of sequentially rendering portions of a web page on the server side and sending them to the client piece by piece, without waiting for the entire page to render.”
Progressive Server Side Rendering (PSSR) is based on the concept of HTML streaming. PSSR breaks pages into meaningful components using code splitting. These parts of the page are controlled by different scripts, and now we have the ability to do hydration independently. Let’s see how PSSR works:
- The browser requests the HTML code from the server.
- The server makes API requests and first renders the critical content and then sends it to the client.
- The browser parses the HTML and displays it on the screen.
- The server renders non-critical content and passes it to the browser.
- The browser then parses and displays non-critical content.
- Meanwhile, JS bundles are loaded and executed in the background, and the browser passes interactivity to the DOM elements.
PSSR improves the performance of your web application by fetching and rendering page components in a parallel and preemptive manner. This approach is known as the progressive hydration method. Features of the progressive hydration method:
- The component is not rendered until it appears in the field of view or is needed for user interaction.
- Loading content on user interaction (scrolling) – much faster than CSR or SSR
- Testing shows that this can shorten the time until the first interactive element appears.
- The experience is better even with slow connections.
In addition, you can use a critical rendering path approach with PSSR to further optimize your application’s performance.
Critical Rendering Steps
Optimizing critical rendering steps refers to prioritizing the location of content that is related to the user’s current activity. The browser does a lot of behind-the-scenes work to make the page experience better. Critical rendering steps are the immediate steps between receiving the HTML, CSS, and JS and the processing required to convert them to visible pixels.
You can shorten the initial render time of your web application by optimizing critical rendering steps
Since you now have a good understanding of client, server, and progressive rendering, you are probably wondering if there is a way to gauge rendering performance. The answer is yes! Chrome DevTools provides a separate tab for monitoring and evaluating rendering performance. Let’s see how we can use it.
Performance analysis with Chrome DevTools
As the interface becomes more feature-rich and complex, it is vital to consider ways to optimize the user experience by reducing both load time and critical path of components. Rendering content to the screen is one of the most expensive processes. To visualize this process, you can use the handy Paint Flashing tool available on the Rendering tab.
The current rendering areas will be highlighted in green if this option is enabled in Chrome. If you see areas that you didn’t intend to render, you can dig a little deeper.
Scrolling performance issues in Chrome DevTools
Scrolling performance issues is another handy tool that you can use to spot any performance issues while scrolling through the page. When this option is enabled, it hangs the label “Repaints on scroll” on the components and highlights in green those components that are rendered when the page is scrolled.
By tracking these performance issues, you can ensure that your web application gives your users the best possible experience.
When developing a web application, it is very important to understand the basic principles of rendering. This knowledge will help you optimize the performance of your web page. By statistics, a one second delay in page load will lower your conversion rate by 7%. On the other hand, long download times can have a devastating effect on app conversion rates. In this article, I’ve covered three rendering techniques and explained why server-side progressive rendering has more advantages over the other two, and how it helps improve the performance of your web application.
- Java developer profession
- JAVA QA engineer
- Frontend developer profession
- Profession Unity Game Developer
- Profession Ethical hacker
- C ++ developer profession
- The profession of iOS developer from scratch
- Profession Android developer from scratch