Fix Google PageSpeed Eliminate render-blocking JavaScript and CSS in above-the-fold content

The Google PageSpeed [1] test “Eliminate render-blocking JavaScript and CSS in above-the-fold content” propose you to delivers your site’s JS and CSS files after the HTML is fully loaded – and, therefore, do not pause your HTML loading to download them.

In order to defer load of your JS files [2], you can either add the async or defer instruction to your scripts links. Async will not guarantee that they are loaded in the same sequence – therefore, if you have several scripts that should run one after the other, defer is preferable to guarantee the sequence :

<script defer type="text/javascript" src="./js/mootools-more-1.4.0.1.js"></script>

For the CSS to be loaded after the full HTML is transmitted, Google proposes [3] this piece of code to add at the end of your HTML, for example after footer closing tag and before body closing tag :

</footer>
 <script>
 var cb = function() {
 var l = document.createElement('link'); l.rel = 'stylesheet';
 l.href = './style.css';
 var h = document.getElementsByTagName('head')[0]; h.parentNode.insertBefore(l, h);
 };
 var raf = requestAnimationFrame || mozRequestAnimationFrame ||
 webkitRequestAnimationFrame || msRequestAnimationFrame;
 if (raf) raf(cb);
 else window.addEventListener('load', cb);
 </script>
</body>

This allowed me to pass the Google PageSpeed [1] test Eliminate render-blocking JavaScript and CSS in above-the-fold content (along with Leverage browser caching [4]) on a website, going up from a score of 51 on mobile (Fig 1) to 72 (Fig 2), and up from 59 (Fig 3) to 79 on desktop (Fig 4).

Fix Google PageSpeed Eliminate render-blocking JavaScript and CSS in above-the-fold content : Fig 1 : Score before eliminating render-blocking JS and CSS in above-the-fold content of 51 on mobile
Fig 1 : Score before eliminating render-blocking JS and CSS in above-the-fold content of 51 on mobile
Fix Google PageSpeed Eliminate render-blocking JavaScript and CSS in above-the-fold content : Fig 2 : Score after eliminating render-blocking JS and CSS in above-the-fold content of 72 on mobile
Fig 2 : Score after eliminating render-blocking JS and CSS in above-the-fold content of 72 on mobile
Fix Google PageSpeed Eliminate render-blocking JavaScript and CSS in above-the-fold content : Fig 3 : Score before eliminating render-blocking JS and CSS in above-the-fold content of 59 on desktop
Fig 3 : Score before eliminating render-blocking JS and CSS in above-the-fold content of 59 on desktop
Fix Google PageSpeed Eliminate render-blocking JavaScript and CSS in above-the-fold content : Fig 4 : Score after eliminating render-blocking JS and CSS in above-the-fold content of 79 on desktop
Fig 4 : Score after eliminating render-blocking JS and CSS in above-the-fold content of 79 on desktop

Similar articles

Comments (10)

Louise Cooper, 2018-08-19
Любовь, читающая ваш контент, продолжайте публиковать
Monica Lindsey, 2018-08-19
Así que así es como lo hacemos, es genial saber
Van Santiago, 2018-08-19
Ótimo, é exatamente isso que eu estava procurando, agora estou pronto
Dwayne Peters, 2018-08-19
당신의 내용을 읽는 것을 좋아하고, 계속 게시하십시오.
Leo Cannon, 2018-08-19
น่าอัศจรรย์ตอนนี้ก็ถึงเวลาที่ฉันจะลอง!
Lawrence Rogers, 2018-08-19
Don’t know how to thank you, but that is pure genius, thanks
Ludanulema, 2018-08-19
Բարեւ, ես տեսա ձեր հոդվածը, եւ դա օգնեց ինձ լուծել խնդիրը, շնորհակալություն
animeg2Q, 2018-08-19
سأحاول ذلك الآن ، شكرًا على المشاركة
Gasfackele, 2018-08-19
To pro mě dobře fungovalo, není třeba se dívat dál
utumikaji0, 2018-08-19
Hej, jag såg din artikel och det hjälpte mig att lösa mitt problem, tack så mycket

Leave a comment