Why do you need to eliminate render blocking CSS, JS?
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.
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,
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, as you are not requesting your browser for an individual external file to load to view your CSS file and it saves many trips from the browser to the server.
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
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.
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.