5 min read

How to Eliminate Render-Blocking Resources

Which CSS and JavaScript files block the first paint, how to find them, and how to fix them with defer, async, critical CSS and smarter loading.

"Eliminate render-blocking resources" means the browser had to wait for some CSS or JavaScript files to download before it could show anything on screen. While it waits, the visitor sees a blank page. Fixing it usually improves First Contentful Paint and Largest Contentful Paint, often by hundreds of milliseconds on mobile.

What makes a resource render-blocking?

When the browser reads the HTML, some files make it stop and wait before it paints the first frame:

  • Stylesheets in the <head> (<link rel="stylesheet">). The browser will not paint until it has all the CSS that applies, so it never shows unstyled content.
  • Synchronous scripts in the <head>, meaning <script src> without defer, async or type="module". The HTML parser stops at each one until it has downloaded and run.
  • CSS @import inside a stylesheet. The imported file is only discovered after the first file arrives, adding another round trip.

Images, fonts and scripts with defer or async do not block the first paint, although fonts can delay when text appears.

How to find the blocking files

  1. Run the page through our CSS performance checker or a full Site Vitals audit. The recommendations list each render-blocking file and the time it is estimated to cost.
  2. Open a waterfall chart of the page. Blocking files sit at the very start, and the first paint cannot happen until the last of them finishes.
  3. In Chrome DevTools, the Network panel's Priority column and the Performance panel show which requests were made before the first paint.

Fixing render-blocking JavaScript

Add defer to scripts that are not needed for the first paint

Most scripts, including your app code, analytics and widgets, do not need to run before the page appears. defer downloads the script in parallel and runs it after the HTML is parsed, in order:

<script src="/js/app.js" defer></script>

Use async for independent scripts

async also downloads in parallel but runs the script as soon as it arrives, in any order. It suits scripts that depend on nothing else, such as some analytics tags. If scripts depend on each other, use defer.

Move inline scripts that need the DOM to the end

Inline scripts in the head that only attach event listeners or read the DOM can move to the end of the <body>, or wait for DOMContentLoaded.

Keep only what truly must run first

A few scripts legitimately need to run before the first paint, such as setting a dark-mode class to avoid a flash of the wrong theme. Keep these tiny and inline.

Fixing render-blocking CSS

1. Remove CSS the page does not use

A full framework or theme stylesheet often contains rules for every component on the site. Purging unused rules at build time (Tailwind does this automatically, and tools such as PurgeCSS do it for other setups) is usually the biggest single win.

2. Split CSS by media

Stylesheets that only apply to print or to large screens can carry a media attribute. The browser still downloads them, but at low priority and without blocking the first paint:

<link rel="stylesheet" href="/css/print.css" media="print">

3. Inline the critical CSS

Critical CSS is the small set of rules needed to style what is visible on the first screen. Inline it in a <style> tag in the head, and load the full stylesheet without blocking:

<style>/* critical rules for the header and hero */</style>
<link rel="preload" href="/css/site.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="/css/site.css"></noscript>

Keep the inlined CSS small (a few kilobytes), because it is downloaded with every page and cannot be cached separately. If the full stylesheet is already small and well cached, a single blocking stylesheet is often fine and simpler.

4. Replace @import with <link> tags or bundling

Each @import adds a round trip. List the files as separate <link> tags so they download in parallel, or let your build tool combine them.

5. Make the CSS you keep arrive faster

  • Serve CSS from your own domain, or preconnect to the CDN that serves it, so no extra connection is needed.
  • Compress with Brotli or gzip and minify.
  • Cache it long-term with a hashed file name, so repeat visits never wait for it. See browser caching explained.

Fonts: not blocking, but often delaying

Web fonts do not block rendering, but text set in a font that has not arrived can stay invisible for up to three seconds in some browsers. Use font-display: swap or optional, self-host the fonts, and preload the one or two files used above the fold. If a Google Fonts stylesheet is in your head, it is a render-blocking request to another domain; self-hosting removes it.

Platform tips

  • WordPress: most blocking files come from plugins and the theme. Performance plugins can defer JavaScript and generate critical CSS, but test carefully: deferring jQuery can break plugins that expect it to be loaded first.
  • Shopify: app scripts are a common source. Remove unused apps and check the theme's theme.liquid for leftover tags.
  • React, Vue and other single-page apps: if the page shows nothing until the JavaScript runs, the whole bundle is effectively render-blocking. Server-side rendering or static generation fixes that at the root.

Common mistakes

  • Adding async to scripts that depend on each other, which breaks them at random.
  • Deferring the CSS for the visible part of the page, which causes a flash of unstyled content and layout shifts. See how to fix CLS.
  • Inlining a huge "critical" CSS block that is bigger than the stylesheet it replaced.
  • Fixing the home page only. Template pages such as blog posts and product pages often load different files.

Check the result

Re-run the page on mobile and compare First Contentful Paint and LCP across a few runs. The render-blocking warning should list fewer files or a smaller estimated saving. Use our website speed test to compare before and after.

Tags:
eliminate render-blocking resourcesrender blocking CSSrender blocking JavaScriptcritical CSSdefer async

Keep reading