[SOLVED] Eliminate Render Blocking Resources

[FIXED] 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.

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.

Font Awesome CSS

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>

Make Sure You Replace "CSS_HERE" With The CSS File Path.

[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.

UPDATE:
26 FEB 2021: Modified The Original Script For Multiple CSS File.

Comments

  1. Thank bro render blocking problems solve hogya ty

    ReplyDelete
  2. In my blog theme, there are three font types, two Googleapis.com and one stack path bootstrapcdn style sheet coding lines

    Should I change all code separately with your code? Please guide me

    ReplyDelete
    Replies
    1. You Can Obtain This By Changing Variables

      Below Is An Example For Files

      https://pastebin.com/dBgF31p3

      Just Change Href Tags With Your CSS Files.

      Delete
    2. I Modified The Original Script For Multiple CSS. You Can Use The Modified Script For Solving Rendering Problem.

      Delete
  3. Hi,

    just 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.

    ReplyDelete
    Replies
    1. Mostly, At The End Of Body Tag So That CSS File Will Be Loaded After The Assets Are Loaded.

      Delete
  4. Hey, I require the same code for JavaScript

    ReplyDelete
    Replies
    1. I Have Already Created One, But Due To Exams I Wasn't Able To Publish The Post.

      Will Be Posting ASAP!

      Stay Tuned...🙌

      Delete
  5. Thanks
    With the help of your code my problem solve.
    Thanks Again

    ReplyDelete
  6. Thanks you for sharing such wonderful information,it works

    ReplyDelete
You Are Welcome To Share Your Ideas With Us In Comments!

Archive

Contact Form

Send