Why do you need to eliminate render blocking CSS, JS?

November 29th, 2018
18 Nov 2017
Kannan Rajendiran
11 Comments

It’s painful when you see your website loading slow, though you have optimized your front-end and the server-side components using the relevant tools and practices. I know how that feels.

What could possibly be the reason, then?

Have you ever given any thought about fixing the render-blocking? Well, this blog will help you with certain useful tips to fix it.

Before jumping in, you need to understand it. Don’t you?.

In easy terms, (Eliminate–remove, Render–layout, design-display webpage, Blocking–stopping) i.e., Render blocking removal.

Every time the browser is loading your web page, the CSS and JS resources also wants to be loaded at first priority before the HTML does. It is default that, CSS is considered as render-blocking resource. Nothing will load until the CSS and JS file loads or parsed. Do you wish to see your page like that?. Heck NO.

Every single CSS and JS files will affect the load time of your page in a huge amount.

But, have you noticed the results in deep, when you put your website’s URL in the pagespeed insights?.

You will find a result section showing the score out of 100 and the exact following statements: (i) Possible Optimizations and (ii) Optimizations Found.

Also, your WordPress websites will be having themes and plugin that adds js and css files to the front-end of your websites. These scripts slows the site load time and also render block of the web page.

 

Here, Now fix the render blocking CSS

The bigger and the larger CSS files will delay the page load much effectively.

But, at the same time, would you like to see a content that hasn’t been styled? Heck NO.

So, you need some CSS files on the page to display an elegant look Above The Fold (ATF), keeping in mind that, this CSS shouldn’t impede the load time of the page.

Know what ATF is?. In a page, when loaded, the content which you are able to see without scrolling is said as Above The Fold (ATF). The content when you scroll and see, is said to be below the fold.

To discover the exact files that are presently blocking the rendering of your webpage, use the tool Page Speed insight developed by Google. This tool will list you the entire files that are blocking a specific page.

In addition to this, Google is following a new algorithm based on LightHouse Chrome, which will be really helpful for monitoring your site’s load time and performance.

Now,

Are you aware, what your browser does at the time when your webpage is rendered?

Firstly, the HTML is analyzed and constructs the DOM – Document Object Model. Secondly, the CSS is analyzed and constructs the CSSOM – CSS Object Model. Both DOM and CSSOM are structural representations of HTML and CSS for the better understanding of the browser.

Then comes the render-tree construction, which is nothing but uniting DOM and CSSOM, that suggests and explains the browser about the part to be rendered and how it needs to be appeared and then lastly comes your website display.

Info: when you make an attempt to render a web page without fixing the render-blocking CSS files, the browser downloads all the CSS resources and displays it.

The Critical Rendering Path is nothing but displaying the files in a line, according to the priority it allocates. This happens before the actual display of the webpage by the browser.

Optimizing critical rendering path is very much recommended for the fastest delivery of the first render.

Every single file eliminated makes an impact in the web page speed.

When you consider eliminating render-blocking CSS, you might think as well think of certain parameters relating to the usage of lesser CSS files, (i) By Combining CSS files, (ii) By Inlining the CSS files

(i) By Combining CSS files

Before getting into this, you need to label your CSS, because once you do the labeling efficiently, you are helping to choose only the chosen CSS files and displays without any delay in rendering.

Info: There may be many little CSS files (due to the plugins and widgets), but there will be a main CSS file which is big. If you are into Adsense, then this blog will be a great deal for you.

How do I combine the CSS files?

All you got to do is a simple copy and a paste work.

If you have many CSS files being called, converge it into one CSS file by just copy pasting it in a new CSS file.

Let’s assume that you have four CSS files,

CSS1,

CSS2,

CSS3,

CSS4

You have to open the “CSS2” and copy all the contents in it and paste it into “CSS1”. In a similar fashion do the same for the rest of the CSS files. You will have one main CSS file which is “CSS1” having all the content of the rest of the three CSS files.

After that, make sure you remove the call for “CSS2”, “CSS3”, “CSS4” from your HTML. Now, you will have only one CSS file instead of four. Think the fast your webpage loads when four files got compressed into one.

Statement given by Ilya Grigorik,

“CSS is a render blocking resource. Get it to the client as soon and as quickly as possible to optimize the time to first render”.

(ii) By Inlining the CSS files

Inline itself means inside-lining.

Put your CSS files in an HTML file.

When you do this, you are helping the browser by reducing the number of files to be downloaded before your webpage is displayed. Also, your browser downloads only the HTML file.

How do I Inline CSS files?

You need to do two things:

Copy the entire contents of the external CSS files and paste it in the Head section of your HTML file between the style tags. Make sure you use the right HTML style tags.

Lesser render blocking and quicker loading of your page takes place in this case.

This is because you aren’t requesting your browser for an individual external file to load for viewing your CSS file and it saves many trips from the browser to the server, thereby reducing Server Response Time.

 

Render Blocking JavaScript (JS) – Eliminate it

This applies when your HTML experiences a render block JavaScript (JS) file in the above the fold part when detected by the pagespeed insight.

Again, refer to the discussions we had in the render blocking CSS as well.

The browser has to build the DOM by analyzing the HTML files every time before it renders a webpage. In doing this, if it comes across any scripts, it stops and checks it and then proceeds with analyzing the HTML. This time duration relates directly to the page drag. You need to fix this.

You can identify your page loading issues by using PageSpeedInsight related to render block JS files.

How do I remove Render blocking JS?

There are three ways.

(i) By the use of Inline JS

(ii) Making JS Asynchronous

(iii) Defer loading of JS

One of the largely used, heavier javascript file, in maximum webpages is, jQuery. You want a fade in and out for an image, then jQuery is a familiar JS file to use.

If you are using jQuery before the initial render and below the fold, then there won’t be any necessity for it to load unless there is a cause.

But if you are using it above the fold, then it goes without saying that you aren’t going by the rules of the regulations and guidelines of what the pagespeed says. In this case, you will have to look in for the HTML file and change where the jQuery’s call is made.

(i) By the use of Inline JS

You should have a lean JS file. Render blocking scripts pushes the browser to halt until they are being downloaded and many round trips for rendering the same.

In the case you having a lean JS file, then you can inline the contents of the JS file in the HTML file and prevent the delay in the page display and quickens the initial render.

By doing this, you need to take care of the HTML file size too.

(ii) Making JS Asynchronous

Why do this? You might have known that, the JS by default stops building DOM and ends up by delaying the time duration for the initial render.

Try using the below script in your HTML,

<script async src=”my.js”>

The following takes place when you use it,

The Asynchronoused scripts are downloaded by the browser

During this process, the browser does not stop for analyzing and or any building of the DOM in the middle. Also, any other scripts needed by the site is not prevented by this process. Until this script is done downloading, the browser not rests for any other actions.

(iii) Defer loading of JS

In simple terms, you can separate the scripts which does not have any impact on your above your fold content, for the initial render and they may be deferred until after the first render or all the important part of the webpage is loaded. This way, resource contention can be reduced and for the performance enhancement.

 

Wrapping up

Always have a concern about the WordPress themes and plugins you are installing, as they use CSS and JS which might be a challenge when it comes to render blocking removal.

Remember, if your webpage calls anything, then it seems to drag your load time.

jQuery forms a pretty good example in this case.

Based on the discussions, reducing the files and inlining them makes the file shrink and does the same work in a faster way which is what is needed for rendering.

Almost all the websites are facing the problem of rendering block. But the question is how to remove them. By following all the useful tips given above, you can easily boost up your load speed of your webpage, though you have done front-end optimization through ideal tools like pagespeed insights and SpeedBoost.

 

So, I believe you will find this blog useful.

I have suggested you from my experience and knowledge. In a similar fashion you might have come across several experiences which is worth.

Share your ideas and the tips you feel which we missed in the comment section.

How do you do the render blocking removal?

 

Kannan Rajendiran

Kannan Rajendiran (Kan) is a technically renowned person and a specialist in providing solutions to almost all type of issues. Love to see clients smile. His expertise in the software industry for more than 15 years helped many clients to provide the best solution, he is a demi-god when website matters. He is the Founder of SpeedBoost :). Extensively attached to the latest technologies and fond of upcoming advancements.
Follow Kannan Rajendiran on

11 Replies to “Why do you need to eliminate render blocking CSS, JS?”

  1. Francesco Esposito says:

    Devo lasciare assolutissimamente la mia esperienza, la mia recensione. . . il programma è fantastico, ti risolve in 10/15s, quello che altri impiegano settimane. Consigliatissimo a chi ha un sito web.

    Italy – Napoli – 7case.it – Agenzia Immobiliare – Mediazione Immobiliare

    ENGLISH TRANSLATION:

    I absolutely must leave my experience, my review. . . the program is fantastic, it solves you in 10 / 15s, what others take weeks. Highly recommended for those with a website.

    Italy – Naples – 7case.it – Real Estate Agency – Real Estate Brokerage

    1. userkan says:

      Thank you Frank, you are a wonderful client. I’m glad SpeedBoost is so helpful to you.

  2. berbagi73 says:

    I still don’t understand how to render blocking CSS and/or JS. If I have 3 css with different potition on my template. how to combine it.

    1. userkan says:

      I’m happy to help you with that. What is your platform? Are you using WordPress as your CMS? Please share your website URL

  3. Inblogslife says:

    Its difficult to understand please can you tell me the deregister code for jquery it was simple but unfortunately i forgot 🙁

    1. userkan says:

      I’m happy to help you. Please refer code,

      wp_deregister_script( string $handle )

      Feel free to reach me if you need more insights.

  4. kaizur ahmed says:

    Excellent blog. But, I still don’t understand how to render blocking or combine CSS and JS file. I have 19 css and 30 js with different portion on my website. How to combine it. I facing problem with https://www.chinesemedicinedoc.com/. Thanks.

  5. Kannan Rajendiran says:

    Hi Kaizur Ahmed,

    I noticed you are on top of WordPress platform.

    1) You must identify the unused CSS and JS for the home page. And dequeue them from the home page.

    2) Defer all the JS (Except the jquery library files) – no need for merging

    3) Merging can be done through cache plugin. You can try W3 total cache

    By the way, I noticed you use JetPack and layer slider. I think you can completely take off their scripts from the home page.

    Please feel free to reach me for further help. Thank you.

  6. Moeez Ahmed says:

    Hye, First of all, A very nice article thanks for sharing with us.
    But I still don’t understand how to combine all CSS files. Right now I have 5 CSS files with the different position on my website. When I was trying to combine all CSS files in one file my website doesn’t open properly. please help me and tell me how to combine all the files in one.

    Thanks in Advance.

    1. Kannan Rajendiran says:

      Moeez Ahmed: Please refer the above comment which I sent to Kaizur

  7. Moeez Ahmed says:

    Hye Kannan Rajendiran,
    Thanks for your reply. And i want to know that how to identify unused CSS and JS for the homepage, means is there any tool for that.

Leave a Reply

Your email address will not be published. Required fields are marked *