Eliminate Render-Blocking Resources With Async and Defer

11 0

Why do we need to eliminate render-blocking resources? Render blocking resources are static files, such as fonts, HTML, CSS, and JavaScript files, vital to rendering a web page. When the browser encounters render-blocking resources, it stops downloading the rest of the resources until these critical files are processed. So the entire rendering process is put on hold.

On the other hand, non-render blocking resources don’t postpone the rendering of the page. The browser can safely download them in the background after the initial page render.
Let’s understand in detail below.

What is Render Blocking Resources?

The process in which the web resources (ex: JS, CSS & HTML files) that are loaded in the webpage potentially cause the browser to block the rendering of the page until they are loaded is called render-blocking resources. These web files can be large with hundreds of kilobytes of data that must be loaded, in addition to the HTML, before it is rendered.

Therefore, always look for the best solution to eliminate render-blocking resources in above-the-fold content and optimize CSS delivery. Two techniques that are widely used are async & defer loading.

What are Render-blocking JavaScripts?

JavaScripts that block the rendering of meaningful content are called ‘Render Blocking JavaScripts.’ They need to be either deferred or use async to eliminate render-blocking resources.

What is Critical and Non-Critical JavaScripts?

CRITICAL: JavaScripts files that are necessary to load during optimized critical rendering.

NON CRITICAL: JavaScript files can wait to load until the first meaningful content (the first paint) of the web page has loaded, called non-critical javascript.

What is Inline Delivery?

Inline delivery refers to load a resource (ex: like JS, CSS) within the HTML code instead of calling/importing that separately.

How to Remove Render Blocking JavaScripts From Website?

To remove render-blocking JavaScripts, developers need to inline critical JavaScript and defer all non-critical JavaScript to eliminate render-blocking resources error.

You may also like to read:

Common Things About Async and Defer

Both async and defer have one common thing. That is, downloading of render-blocking javascript doesn’t block page rendering. So the visitors may read webpage content & get acquainted with the webpage immediately.

Why Should We Defer Loading of JavaScripts?

When the web browser comes across a javascript, it executes the script first before continue to load HTML that includes the content users are looking for. It means that JavaScripts are one of the major culprits to make your website slow.

For a browser, executing JavaScript is a heavier task as it depends on the size of the javascript. Also, it takes more time than rendering the meaningful content (the first paint) of the webpage.

Eliminate Render-Blocking Resources With Async and Defer

Hence JavaScript affects the critical rendering path and slows down the page speed of your site. Also, defer loading heavier task of JS execution so that critical rendering path remain uninterrupted.

How to Identify Render-Blocking JavaScripts on Your Website?

You can easily identify render-blocking JavaScript(s) of your website by using site speed testing tools. You can see the results below for this article when we have gone through the google page speed test:

Eliminate Render-Blocking Resources With Async and Defer
This Page Results – Eliminate Render-Blocking Resources With Async and Defer

There are several page speed testing tools available to analyze a website for site speed and loading time. The most reliable and trusted tools for page speed testing are:

1. PageSpeed Insights by Google
2. GTmetrix
3. Pingdom Tools

Test your website using the above speed testing tools. And analyze the results of these tools so that you can compare the results before and after implementing defer parsing of JavaScript(s).

What Does Defer Mean in JavaScript?

Defer literally means ‘hold back’ or ‘delay.’ If you use the ‘defer’ attribute in <script> for parsing (loading) of JavaScript, JavaScript will execute only after the HTML parsing has finished. This helps to improve the speed of a webpage.

Does Async or Defer Attributes Have any Effect on Inline Scripts?

No, both async & defer attributes don’t have any effect on inline scripts.

What is Defer Parsing of JavaScript?

Usually, Googe Pagespeed Insights (PSI) or other site speed testing tools (GTMetrix, etc.) show warning/error, Eliminate render-blocking Resources if your website loads JavaScript(s) that block the loading of meaningful content (the first paint) of your site.

According to Google PageSpeed Insights (PSI) recommendations, your website should deliver critical JS inline and defer all non-critical JS to eliminate render-blocking resources.

Therefore, defer parsing of JavaScript means JavaScript(s) should load only after the website’s content has loaded to pass eliminate render-blocking resources error.

What’s the Main Reason to Defer Loading of JavaScript?

As you know,  the browser gives priority to execute the scripts over parsing the HTML. However, the fact is, most of the JavaScripts are used only when the complete web page is loaded. Examples are animation, effect, or some functionality, etc.

Therefore, it is good to load JavaScript(s) only after the content has been loaded.

Advantages of Deferred Loading of JavaScript

The advantages of deferred loading of JavaScript are:

1. It deferred loading of JavaScript does not affect the critical render path

2. It consequently helps to speed up your website.

3. It gives a better user experience to your website visitors.

4. It makes your site load faster

5. It helps improve your search ranking on desktop as well as mobile.

6. It helps improve the performance of websites.

7. It allows the elimination of render-blocking JavaScript.

What is Defer Parsing?

Whenever a browser encoun­ters a javascript with the defer attribute, it will follow the below steps sequentially.

  1. First, make par­al­lel requests to fetch the indi­vid­ual files.
  2. Meanwhile, Con­tinue pars­ing the doc­u­ment as if it was never interrupted.
  3. Then, Fin­ish task of pars­ing the web doc­u­ment even if the javascript files are downloaded.
  4. Once the parsing documents’ task is finished, Exe­cute each script in the order they were encoun­tered in the document.


<script src=”myjavascriptfile1.js” defer></script>
<script src=”myjavascriptfile2.js” defer></script>

Therefore, Defer is very sim­i­lar to async attribute with just one major dif­fer­er­ence.

More interesting topics for you:

How Do You Defer JavaScript?

With HTML V5, two new boolean attributes for the <script> tag has been introduced. They are async and deferAsync attribute allows the execution of javascript files asynchronously. But, the defer attribute allows execution only after the whole document has been parsed.

The webpage would have to load and execute scripts before finishing to render the page.

Here’s a usage example of defer attribute of <script>:

<script defer src=”/js/jquery.min.js”> </script>

How to Defer Loading of JavaScript in WordPress?

You can defer parsing of JavaScript in WordPress by following three methods:

  1. Using WordPress Plugins.
  2. Using the Script method (without using plugins).
  3. Adding a Code Snippet to function.php file.

Advantages of Async Loading of JavaScript

Advantages of async loading of JavaScript are

1. It allows the elimination of render-blocking JavaScript.

2. async loading of JavaScript does not affect the critical render path.

3. It consequently helps to speed up your website.

4. It gives a better user experience to visitors of websites.

5. It makes your website load faster.

6. It helps to improve your search ranking on desktop as well as mobile.

7. It helps to improve the performance of websites.

How Do You Async Attribute in JavaScript?

When you add the async attribute to your script tag, the fol­low­ing steps likely will happen.

  1. It makes par­al­lel requests to fetch the files.
  2. It con­tinue parsing/loading the doc­u­ment as if it was never interrupted.
  3. Exe­cute the indi­vid­ual scripts the moment the java files are downloaded.


<script src=”javascript1.js” async></script>

Difference Between Async & Defer Loading?

Async and defer similar in that they allow scripts to load without blocking the HTML parsing. It means users see page content more quickly. But they do have differences in eliminate render-blocking resources.

Here are the main difference between async and defer JavaScript

1. The defer attribute delays JavaScript execution until HTML parsing has been completed. Whereas with the async attribute, HTML parsing & script execution happens simultaneously, and the script executes as soon as it’s ready.

2. Scripts loaded with async are parsed and executed immediately when the resource is done downloading. Whereas scripts with defer attributee don’t execute until the HTML doc is done being parsed.

3. Async scripts may load out-of-order, whereas defer scripts are executed in the order in which they appear in the markup.

4. Async follows Load-first order. Here the order of document doesn’t matter. It may load and execute while the document has not yet been fully downloaded. It also happens if scripts are small or cached and the document is long enough. whereas defer follows Document order (as they go in the document). It executes after the document is loaded and parsed (they wait if needed), right before DOM Content Loaded.

Why We Prefer Defer Over Async?

Though Both async and defer cause JavaScript execution to happen at different times on the web page to eliminate render-blocking resources.

Defer causes javascript execution to happen at the same time as or later than async. It is because javascript is made defer or async & is less important for the web page’s critical content. Therefore, it’s better to defer so that their execution happens outside of the main rendering time.

Defer scripts can never block synchronous scripts. Whereas async scripts depend on how quickly they download. Synchronous scripts are typically made synchronous because they are important for the critical content on the webpage.

Therefore, it’s always better to use defer, so synchronous scripts are not blocked from executing. Also, their critical work is completed more quickly.

Which is Better Async or Defer?

While using an async attribute, the JavaScript file gets downloaded asynchronously & then executed as soon as it’s downloaded.

Whereas with the defer attribute, the file gets downloaded asynchronously. But executed only when the document loading is completed. Also, scripts will execute in the same order as they are called.

Assume we are using jQuery as well as other javascript that depend on it. We defer on them (jQuery included), making sure to call jQuery before the dependent scripts.

Eliminate Render-Blocking Resources With Async and Defer

Therefore, defer is the right choice of attribute when a script depends on another script. And, defer is the right choice when async is not an option.

FAQs: Eliminate Render-Blocking Resources With Async and Defer

  1. Are images render blocking?

    Remember, images aren’t rendered blocking, so if you have images on the blue DOM line, you can safely ignore those, although you will still want to optimize your images.

  2. What is CSS render blocking JavaScript?

    Render blocking JavaScript and CSS are files that prevent a website from displaying a web page before loading these files.

  3. What is inline CSS?

    Inline CSS allows you to apply a unique style to one HTML element at a time. You assign CSS to a specific HTML element using the style attribute with any CSS properties defined within it.

Conclusion: Eliminate Render-Blocking Resources With Async and Defer

So, we have discussed best strategies to eliminate render-blocking resources.

  • Don’t use CSS imports.
  • Load conditional CSS with media attributes
  • Use the defer and async attributes to eliminate render-blocking JavaScript.
  • Split, bundle, and minify CSS and JavaScript files
  • Try to load all custom fonts locally

To help visitors load the visible portion of your page more quickly, you should delay loading resources that aren’t immediately required.

11 0

Want more stuff like this?

Every week we’ll send you advice, tips, and in-depth tutorials free of cost!

Don’t worry; we don’t spam. You can unsubscribe here anytime.

Leave a Comment