Fix Render-Blocking Resources
Render-Blocking Resources
- Problem: JavaScript or CSS files block the browser from rendering the page until they are downloaded and processed.
- Why it fails: Increases LCP and First Contentful Paint (FCP), making the page appear slow.
- How to Fix "eliminate render-blocking resources":
- Defer Non-Critical JavaScript: Add the
deferorasyncattribute to<script>tags.deferexecutes scripts in order after the HTML is parsed;asyncexecutes whenever ready, potentially out of order. Usedeferfor most cases unless script order doesn't matter.<script src="analytics.js" defer></script> <script src="main-app-bundle.js" defer></script> - Inline Critical CSS: Identify the minimal CSS needed to style the above-the-fold content and include it directly in a
<style>tag in the<head>. - Load Non-Critical CSS Asynchronously: Use techniques like
media="print"onload trick or JavaScript to load stylesheets that aren't needed immediately.<link rel="stylesheet" href="non-critical.css" media="print" onload="this.media='all'"> <noscript><link rel="stylesheet" href="non-critical.css"></noscript>
- Defer Non-Critical JavaScript: Add the