designwithfocus

Page speed & performance

How to Optimize the Critical Rendering Path

By Design With Focus Team 7 min read
A short chain of HTML, CSS, and script files leading to a painted page

Short answer

Optimize the critical rendering path by cutting blocking resources, the bytes in them, and the length of the chain. The browser builds a DOM and a CSSOM, runs JavaScript that changes them, then builds a render tree, lays out, and paints. CSS in the head blocks rendering. A plain script in the head blocks the parser.

Last verified against the sources listed below.

Key takeaways

  • web.dev defines the critical rendering path as the steps before the browser's initial render.
  • The path builds a DOM, a CSSOM, and a render tree, then lays out, paints, and composites.
  • Render-blocking CSS in the head and parser-blocking scripts are the resources that hold the first paint.
  • The optimizing guide names three cuts: fewer critical resources, fewer critical bytes, and a shorter chain.
  • Fonts and images usually do not block the initial render, but a missing image size can shift layout later.

How to optimize critical rendering path length starts with a shorter wait before the first paint. The browser needs the HTML and the blocking CSS and JavaScript that decide that paint, and nothing else should hold it.

Page speed includes that wait, then the later paints that fill in images and fonts. This guide stays on the first one.

What is on the critical path?

The critical rendering path is the sequence the browser runs before the initial render, and it waits only for resources that paint needs.

web.dev’s critical-path lesson lists the steps. The browser constructs the DOM from the HTML and the CSSOM from the CSS. It applies JavaScript that changes either model.

It builds a render tree, runs style and layout, paints pixels in memory, composites overlaps, and draws the result to the screen. The user sees content only after that sequence.

MDN describes the DOM as the in-memory tree of the document, and the CSSOM as the APIs that read and change CSS. The CSSOM specification says CSS describes the rendering of structured documents. Those two trees are why a missing stylesheet or a blocking script delays pixels.

The same lesson says the browser processes HTML as a stream and can paint before the rest of the file arrives. It does not typically wait for every image, every font, or every script outside the head.

What do you need before editing?

You need the page URL, a waterfall or a Lighthouse run, and a list of files that actually delay the first paint.

WebPageTest marks render-blocking resources and draws the start-render line after those files are downloaded and processed. Lighthouse flags a render-blocking resource when it delays rendering, so it can stay quiet about a file that is blocking in theory but not on this page. Use both if you have them.

One report is enough to start.

Chrome’s write-up of the old “Eliminate render-blocking resources” audit says that audit moved into the Render-blocking requests insight in Lighthouse 13. The rules it prints are still useful. A script in the head is flagged when it lacks defer and async.

A stylesheet is flagged when it is not disabled and its media does not limit it to some other device. media="all" still counts as render-blocking.

The Coverage tab in Chrome DevTools, described on that Chrome page, colors CSS and JavaScript that the first paint used and code that it did not. That split is your candidate list. It is not a ranking of design quality.

How do you shorten the path?

Cut the number of critical resources, then the bytes in the ones you keep, then the length of the chain between them.

Ilya Grigorik’s optimizing article, published March 31, 2014, names those three variables. A critical resource can block the initial render. Critical path length follows the dependency graph and the size of each file, because some downloads start only after an earlier file is processed, and a larger file can take more round trips.

Fewer critical bytes means the browser can process and paint sooner.

  1. Write down the critical resources, their transfer size, and which file discovers the next one.
  2. Remove critical resources you can drop, or mark scripts async or defer so they leave the blocking set.
  3. Shrink the remaining files by deleting unused CSS and JavaScript and by compressing what is left.
  4. Load the resources you still need as early as possible so the chain does not grow behind a late discovery.
  5. Re-run the same waterfall and confirm the start-render line moved for a reason you can name.

Do not invent a millisecond target. The articles tell you which direction is faster. Your waterfall tells you whether this page moved.

Which files should stop blocking?

CSS in the head and synchronous scripts are the default blockers. Fonts, images, and late scripts usually are not.

Resource Default effect on the first render A way to take it off the critical path
Stylesheet in the head Render-blocking until it is processed Inline only the CSS the first paint uses, or give other files a media query that does not match yet
Script in the head without async or defer Parser-blocking, so rendering waits too Add async or defer, or move non-critical script out of the head
Image Not typically required for the initial render Compress it and set width and height so later layout does not jump
Web font Not typically required for the initial render Expect a later paint. Do not treat the font file as the thing holding the first pixels
CSS with a non-matching media attribute Not render-blocking for this viewport Keep print or other unused media off the first paint

CSS is render-blocking because an unstyled first paint can look broken. web.dev says that pause is intentional. The mistake is shipping every rule in that first file.

Chrome’s guide suggests inlining the CSS the first paint needs and loading the rest without blocking. It also says to minify.

Images are the usual place bytes hide. An image compressor cuts the transfer size of a file the first paint may not wait for. That still helps the next paint, and it helps LCP when the largest element is a picture.

It is a different cut from removing a blocking stylesheet.

What if the first paint is still late?

Match the symptom to the file that is still on the chain, then change that file only.

What you see Likely cause What to change
Start render sits behind one CSS file That stylesheet is render-blocking Split out rules the first screen does not use, or inline the small critical slice
The parser pauses on a script in the head The script is synchronous Add defer or async if the script does not need to run at that exact point
HTML arrives late, before any CSS Time to first byte is the wait The critical-path lesson points this at the earlier TTFB work, not at more CSS tricks
First paint is fast, then the hero pops in The hero is a font or image, not a blocking file Optimize that file for the contentful paint, and reserve its box
Lighthouse lists one blocker and WebPageTest lists several Lighthouse skips resources that did not delay this run Fix the file both tools agree on first

A preload scanner can download later resources while a synchronous script blocks the parser. web.dev calls that a help, not a substitute for keeping the script off the parser. blocking=render on a link, script, or style, added in Chrome 105, can mark an element as render-blocking while the parser continues.

Use it when you need a file to hold the paint and you do not want it to hold the parser too.

After each change, reload the report. The path is shorter when the blocking list is shorter, the bytes on that list are smaller, or a dependency starts earlier. Those are the three checks the optimizing article gives you.

Frequently asked questions

Do images sit on the critical rendering path?

Usually no. web.dev's critical-path lesson says the browser does not typically wait for images, fonts, or all of the HTML before the initial render. It also does not wait for non-render-blocking JavaScript outside the head, or for CSS whose media attribute does not match the viewport. Images are filled in on a later render. If the HTML does not reserve the image size, the layout can shift when the file arrives.

Why does a script in the head block the page?

A script can change the DOM or the CSSOM, so the parser stops until it knows what the script did. web.dev calls that parser-blocking, and it says parser-blocking resources are render-blocking as well, because the parser cannot reach the content after the script. async, defer, or module on the script element changes that default. A script at the end of the body is outside the head, so it is not the resource the critical-path lesson treats as blocking the whole page.

Does every stylesheet block the first paint?

CSS blocks rendering by default, whether it is a style element or a linked file. web.dev notes that a media attribute which does not match the current viewport can keep that file from blocking. Chrome's Lighthouse write-up says a disabled stylesheet is not downloaded, and that media=all is still treated as render-blocking. Some browsers only block content below the stylesheet once they have discovered it. For the first paint of the whole page, styles in the head are the ones that matter.

What is the difference between first paint and LCP?

The critical rendering path, as web.dev describes it, ends at the initial render. The same lesson says newer metrics ask whether that endpoint should be the first paint or a contentful paint such as Largest Contentful Paint or First Contentful Paint. A contentful path can include files that are not render-blocking, including the image or font that is the main content. Shortening the classic path still helps.

Will this guide's steps name a millisecond saving?

No. The two web.dev pages opened here tell you to reduce critical resources, critical bytes, and critical path length. They do not publish a universal millisecond saving for those cuts. Lighthouse and WebPageTest can show which URLs block a specific page, and the waterfall's start-render line shows when that page painted. Copy the resources from your own report. Do not borrow a timing from a different site and treat it as your result.

Sources