[SOLVED] Eliminate Render Blocking Resources
Eliminate Render Blocking Resources
Yesterday When I Checked My Blog Speed On Google Insight, The Blog Score Was very LOW!. The Blog Speed Was Very Low Because Of Number Of Externally Linking CSS And JAVASCRIPT Files.
Table Of Contents
The Problem My Blog Was Facing Was To "Eliminate Render Blocking Resources" It Was Showing A CSS File Causing This Problem. After Inspecting In Chrome Developer. It Was Font-Awesome Stylesheet Causing This Problem.
After Searching This Problem On The Internet, I Found That There Is No Solution, But Some Of Them Recommended To Put The CSS File In The HEAD Of The Page That Is To Place The CSS File Just Below <head> To Eliminate Render Blocking Resources.
I Figured It Out That Not Most Of The CSS Files Causes This Problem, When I Checked These Problems On My Other Blog Most Of The Blog Don't Have This Problem. Then, I Checked For The Size Of Font-Awesome CSS. It Weights Around 455~78KB.
CSS Files Having A Large Size Causes This Problem While Page Loading. So I Decided To Find A Solution For This Problem.
I Came Across Lazy Loading Stylesheet For HTML Pages. I Implemented The Same In Blogger And Found That It Worked In Blogger And Also Solved "Eliminate Render Blocking Resources" Problem.
Lazy Load Stylesheet Script (SINGLE)
<!-- IF BROWSER DOESN'T SUPPORT JAVASCRIPT THEN USE NORMAL LINK TAGS TO LOAD CSS -->
<noscript>
<link rel="stylesheet" type="text/css" href="CSS_HERE"/>
</noscript>
<!-- LOAD CSS -->
<script type="text/javascript">//<![CDATA[
(function() {
var css = document.createElement('link');
css.href = 'CSS_HERE';
css.rel = 'stylesheet';
css.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(css);
})();
//]]></script>
As Some Of The User Were Having Two Or More Rendering CSS, I Modified The Original Script For Argument Based.
You Can Use Below Script If You Have More Than One Rendering CSS.
Lazy Load Stylesheet Script (MULTIPLE)
<!-- IF BROWSER DOESN'T SUPPORT JAVASCRIPT THEN USE NORMAL LINK TAGS TO LOAD CSS -->
<noscript>
<link rel="stylesheet" type="text/css" href="CSS_HERE"/>
<link rel="stylesheet" type="text/css" href="CSS_HERE"/>
<link rel="stylesheet" type="text/css" href="CSS_HERE"/>
</noscript>
<!-- LOAD CSS -->
<script type="text/javascript">//<![CDATA[
function lazycss(url) {
var css = document.createElement("link");
css.href = url;
css.rel = "stylesheet";
css.type = "text/css";
document.getElementsByTagName("head")[0].appendChild(css);
}
// LOAD CSS
lazycss("CSS_HERE");
lazycss("CSS_HERE");
lazycss("CSS_HERE");
//]]></script>
[PROOF] Lazy Loading Stylesheet (VIDEO)
NOTE:
It Is Not Recommended To Use The Script For Main CSS (Body CSS) It Can Make Your Blog Look Ugly While Loading.
26 FEB 2021: Modified The Original Script For Multiple CSS File.
Thanks
ReplyDeleteWelcome 😊
DeleteThank bro render blocking problems solve hogya ty
ReplyDeleteWelcome 😊
DeleteIn my blog theme, there are three font types, two Googleapis.com and one stack path bootstrapcdn style sheet coding lines
ReplyDeleteShould I change all code separately with your code? Please guide me
You Can Obtain This By Changing Variables
DeleteBelow Is An Example For Files
https://pastebin.com/dBgF31p3
Just Change Href Tags With Your CSS Files.
I Modified The Original Script For Multiple CSS. You Can Use The Modified Script For Solving Rendering Problem.
DeleteHi,
ReplyDeletejust wanted to understand now that i have changed that CSS into script kinda things now so where i should put this code in head or in footer as usual we do with scrtps.
Mostly, At The End Of Body Tag So That CSS File Will Be Loaded After The Assets Are Loaded.
DeleteHey, I require the same code for JavaScript
ReplyDeleteI Have Already Created One, But Due To Exams I Wasn't Able To Publish The Post.
DeleteWill Be Posting ASAP!
Stay Tuned...🙌
Thanks
ReplyDeleteWith the help of your code my problem solve.
Thanks Again
Welcome 😊
DeleteThanks you for sharing such wonderful information,it works
ReplyDeleteWelcome 😊
Delete