Skip to content
YouTurkey Tech
All latest tech topics

The critical rendering path

Intermediate

Everything between the first byte of HTML and the first pixel: render-blocking CSS, a parser-blocking script, layout and paint, FCP and LCP, and what defer changes.Builds on What happens when you type a URL, How the browser builds the DOM

Timeline

Empty

0/15Press Play, or step through with the arrows, to begin.
Step 0 of 15

Explanation

3 min read

On this page

What is the critical rendering path?

The critical rendering path is the chain of work a browser must finish before it can show the first pixels of a page: download the HTML, parse it into the DOM, get the CSS and build the CSSOM, combine them into the render tree, compute the , and paint. Anything that delays one link delays the first paint.

Two kinds of resources sit on that path:

  • Render-blocking CSS. The browser will not paint until the stylesheets in the <head> are downloaded and parsed, because painting without them would show unstyled content and then jump. CSS does not stop the HTML parser.
  • Parser-blocking scripts. A plain <script src> stops the parser until the script is downloaded and has run, because the script could change the document (document.write, adding elements). It also waits for the stylesheets before it, since it may read styles.

What is the difference between defer and async?

Both download the script without stopping the parser. They differ in when it runs:

  • defer runs the script after the whole document is parsed, before DOMContentLoaded, and deferred scripts keep their order. Use it for scripts that work with the page. Module scripts (type="module") are deferred by default.
  • async runs the script as soon as it has downloaded, pausing the parser at that moment, in no particular order. Use it for independent scripts like analytics.
  • Neither means the parser stops at the tag. Avoid it in the <head> unless the script must run before anything is shown.

What are Core Web Vitals?

Google's Core Web Vitals measure how a page feels to real visitors, at the 75th percentile:

  • LCP, Largest Contentful Paint: when the biggest image or text block is painted. Good: 2.5 s or less.
  • INP, Interaction to Next Paint: how fast the page responds to clicks, taps and key presses. Good: 200 ms or less.
  • CLS, Cumulative Layout Shift: how much the layout jumps while loading. Good: 0.1 or less.

FCP, First Contentful Paint, is not a Core Web Vital but a helpful early signal: the first text or image on screen. Good: 1.8 s or less.

What mistakes do people make with the critical rendering path?

Mini example

The same page, with its script deferred and its main image marked as important:

<head>  <link rel="stylesheet" href="style.css" />  <script src="app.js" defer></script></head><body>  <h1>Today's deals</h1>  <img src="hero.jpg" alt="Sale banner" width="1200" height="600" fetchpriority="high" /></body>

Quick check

Which script attribute runs the script after the document is parsed, keeping the order of scripts?

Further reading

All steps as text
  1. Step 1:

    The browser requests the page. Nothing can start until index.html arrives over the network, here at 100 ms.

  2. Step 2:

    The parser starts reading the HTML from the top, building the DOM.

    Lines 1–4

  3. Step 3:

    It finds the stylesheet and starts downloading it. Parsing goes on, but nothing can be painted until the CSS is ready: CSS is render-blocking.

    Line 5

  4. Step 4:

    Then a plain script. The parser has to stop: the script could change the page, so it must download and run first.

    Line 6

  5. Step 5:

    While the parser waits, the preload scanner reads ahead and starts downloading hero.jpg early.

    Line 10

  6. Step 6:

    style.css arrives and is parsed into the CSSOM: every style rule, ready to apply.

    Line 5

  7. Step 7:

    app.js only arrives at 400 ms, then runs. All this time the parser has been stopped, and the page is still blank.

    Line 6

  8. Step 8:

    Parsing resumes and reaches the end of the body. The DOM is complete.

    Lines 8–11

  9. Step 9:

    The DOM and the CSSOM combine into the render tree: every visible element with its computed styles.

  10. Step 10:

    Layout works out the size and position of every box on the page.

  11. Step 11:

    Paint turns the boxes into pixels: the heading and text appear. That is First Contentful Paint, FCP, at 515 ms.

    Lines 9–11

  12. Step 12:

    hero.jpg arrives at 600 ms and is painted. It is the biggest element on screen, so this is Largest Contentful Paint, LCP.

    Line 10

  13. Step 13:

    With <script defer>, the parser never stops: the script downloads alongside and runs after parsing. FCP moves from 515 ms to 270 ms.

    Line 6

  14. Step 14:

    LCP barely moves: it waits for hero.jpg, not the script. To improve it, make the image smaller or start loading it sooner.

    Line 10

  15. Step 15:

    CSS blocks rendering, plain scripts block parsing, and both sit on the critical path. Keep CSS lean and defer scripts, and the first paint comes sooner.