How do you eliminate render-blocking resources for faster page load?
guide // , 5 min read, by Darthwares
To eliminate render-blocking resources, inline your critical assets, defer non-critical styles and scripts, and remove unused code. Render-blocking refers to any part of the webpage loading process that stops the browser from rendering the user interface. Initially-loaded CSS and JavaScript files are the most common causes of these rendering delays.
On this page // 7 sections
- 01What are render-blocking resources?
- 02Why do CSS and JavaScript block page rendering?
- 03How do you identify render-blocking resources on a page?
- 04How do you eliminate render-blocking CSS?
- 05How do you eliminate render-blocking JavaScript?
- 06How do you diagnose and fix render-blocking symptoms?
- 07Common questions
The short version
- Render-blocking CSS and JavaScript increase the time users wait to view page content or interact with controls.
- Google Lighthouse flags render-blocking scripts and stylesheets during page audits.
- The Coverage tab in Chrome DevTools shows how much CSS and JavaScript is actually used during initial page load.
- You can make CSS non-render blocking by using media queries, inlining critical styles, and loading non-critical stylesheets asynchronously.
- JavaScript blocking is eliminated by adding async or defer attributes to script elements, or linking scripts after DOM elements.
What are render-blocking resources?
MDN Web Docs defines render-blocking as any part of the site loading process that blocks the rendering of the user interface. The most common causes are initially-loaded CSS or JavaScript files. When a web browser encounters these render-blocking URLs, it pauses displaying content until the files are downloaded and processed.
Render-blocking is bad for web performance because it increases the length of time until users can interact with the site. Users cannot view page content or interact with controls while the browser waits for blocking files. Removing or deferring these resources allows the screen to paint much faster.
Why do CSS and JavaScript block page rendering?
Documentation on web.dev explains that CSS is treated as a render-blocking resource by default. The browser will not render any processed content until the CSS Object Model, or CSSOM, is fully constructed. Linking stylesheets using traditional link tags with rel="stylesheet" is synchronous and forces the rendering process to wait. Web pages that contain unnecessarily large stylesheets take longer to render, though minifying CSS files reduces file sizes to make downloads quicker.
JavaScript files block HTML parsing when loaded without execution attributes. When loading script elements without defer or async attributes, the browser halts HTML parsing and page rendering until the script file is downloaded, parsed, and executed. These un-attributed tags act as parser-blocking resources that interrupt page construction.
How do you identify render-blocking resources on a page?
The first step toward reducing the impact of render-blocking resources is identifying what is critical and what is not. Chrome for Developers documents that Lighthouse audits flag two specific types of render-blocking URLs: scripts and stylesheets.
Developers can analyze code utilization directly within Chrome DevTools using the Coverage tab. The coverage report displays how much of your CSS and JavaScript is actually used during the initial page load. Unused or non-critical code identified in this report can be deferred or removed.
- 01Run an automated performance audit using Google Lighthouse to reveal flagged render-blocking scripts and stylesheets.
- 02Open Chrome DevTools and navigate to the Coverage tab to start recording code execution.
- 03Inspect the coverage report to determine the exact proportion of unused CSS and JavaScript loaded on initial render.
How do you eliminate render-blocking CSS?
Eliminating blocking CSS requires separating critical styling from rules that are not needed immediately. Media types and media queries allow developers to mark specific CSS resources as non-render blocking. These queries tailor presentation to specific use cases, such as print stylesheets, or dynamic conditions like screen orientation changes and screen resizing. The browser still downloads all CSS resources, but non-blocking files do not hold up the rendering process.
MDN Web Docs outlines a method to load CSS asynchronously by setting the stylesheet media type to print, then changing it to all once loaded. A style sheet reference inside a noscript element provides a fallback for browsers that do not execute JavaScript. Combining asynchronous loading with inlined critical CSS reduces the impact of render-blocking stylesheets.
How do you eliminate render-blocking JavaScript?
The script element in HTML is used to embed or refer to executable JavaScript code. Developers avoid JavaScript blocking by using the async or defer attributes, or by linking JavaScript assets after the page DOM elements. Adding these attributes eliminates parser-blocking JavaScript where the browser would otherwise have to load and evaluate scripts before continuing to parse HTML.
Scripts loaded using the async attribute download the script file in the background without blocking page parsing while fetched. Scripts loaded with the defer attribute allow HTML parsing to proceed uninterrupted and delay execution. MDN Web Docs notes that scripts with the defer attribute prevent the DOMContentLoaded event from firing until the script has loaded and finished evaluating.
How do you diagnose and fix render-blocking symptoms?
Systematic performance audits map specific render-blocking symptoms to developer checks and technical fixes. Use the diagnostic table below to match observed browser bottlenecks with grounded remediation techniques.
| Symptom | Diagnostic check | Corrective action |
|---|---|---|
| Lighthouse flags render-blocking script or stylesheet URLs | Open the Coverage tab in Chrome DevTools to measure unused code on initial load | Inline critical resources, defer non-critical resources, and remove unused code |
| HTML parser stops processing DOM elements while loading JavaScript | Inspect script tags for missing async or defer attributes | Add async or defer attributes to script tags, or link JavaScript assets after DOM elements |
| Slow initial paint due to delayed CSSOM construction | Check total CSS file size and examine link element media attributes | Minify CSS files to speed downloads, and use media queries to mark conditional styles as non-render blocking |
Common questions
What are render-blocking resources?
Render-blocking resources are parts of the website loading process, primarily initially-loaded CSS and JavaScript files, that delay the browser from rendering the user interface.
Which types of render-blocking resources does Lighthouse flag?
Google Lighthouse flags two specific types of render-blocking URLs: scripts and stylesheets.
What is the difference between the async and defer attributes for scripts?
The async attribute downloads the script without blocking page parsing while fetched. The defer attribute also downloads asynchronously but prevents the DOMContentLoaded event from firing until the script has finished loading and evaluating.
Does the browser still download CSS files that are marked non-render blocking?
Yes. The browser downloads all CSS resources regardless of whether they are marked as render-blocking or non-blocking.
Primary sources and further reading
This article was researched and written by an AI model and published automatically. It was written from sentences that were checked to appear on the pages below, but a person has not reviewed the text. If something is wrong, tell us at chibivikramathithan@darthwares.com and we will correct it.