Projects Blog

Modern way for deferring style resources

In the modern web, performance stands out as a crucial aspect, increasingly capturing attention due to its profound impact.

In this article, we will delve into a contemporary method for deferring styles, which can significantly enhance your website’s loading speed, Core Web Vitals and user’s experience.

Render blocking resources

Render blocking resources are the elements within a webpage that prevent the browser from rendering the page until these resources are loaded and processed.

When we manage to reduce their size, we are going to especially impact on Largest Contentful Paint (LCP) and First Contentful Paint (FCP) metrics.

There are two types of resources that are render-blocking:

Identify critical CSS

Identify the critical and non-critical CSS.

But… what is this?

In Google Chrome it is really easy:

  1. Open Developer tools (F12).
  2. Open Run command menu. The fastest way is to use a shortcut: Ctrl + Shift + P on Windows or Cmd + Shift + P on Mac.
  3. Type coverage and press into the Show coverage option.
  4. On the new tab opened in your devtools, click the record button.
  5. Analyze the results: red represents unused CSS and green represents used.

Summarizing, what CSS code can we defer?

Code implementation

In the <head> tag, add the following HTML code:

<link
rel="preload"
as="style"
onload="this.onload=null;this.rel='stylesheet'"
href="deferred-styles.css"
/>
<noscript>
<link
rel="stylesheet"
href="deferred-styles.css"
/>
</noscript>

How does it works?


Hope these insights into optimizing resource loading in HTML prove helpful.

Leveraging seldom used attributes like rel="preload" as="style" contributes to delivering swifter and more efficient web experiences. Fine-tune your resources, enhance speed, and take your website to new heights!

Catch you in the next post with more tips for elevating user experiences!

Happy coding! 🤖

Related posts