Skip to content

Lesson 3 of 9 · 27m

The Critical Rendering Path: What Must Happen Before Pixels

Understand HTML parsing, CSSOM, render tree construction, layout, paint, and compositing well enough to remove real blockers instead of cargo-culting async attributes.

The browser is not being mysterious when it refuses to paint. It is waiting for inputs it believes are required to produce correct pixels. Most first-paint failures are dependency failures: CSS discovered late, synchronous JavaScript in the head, fonts treated carelessly, or server output delayed until everything is perfect. Once you can recite the critical rendering path, optimization stops being a list of tricks.

The browser pipeline, compressed

At a practical level, first render works like this:

HTML bytes -> DOM tree
CSS bytes  -> CSSOM tree
DOM + CSSOM -> render tree
render tree -> layout -> paint -> composite

CSS is render-blocking because layout depends on the CSSOM. Synchronous scripts are parser-blocking because they can inspect or mutate the DOM and CSSOM. A script in the head therefore has a nasty double effect: it pauses HTML parsing and waits for CSS.

Put only critical CSS in the critical path

A large global stylesheet delays first paint even when most rules are for routes the user is not viewing. The traditional fix is critical CSS for above-the-fold layout plus deferred full CSS:

<style>body{margin:0;font-family:system-ui,sans-serif}.hero{min-height:420px}</style>
<link rel="preload" href="/assets/app.8f3a1c.css" as="style"
      onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="/assets/app.8f3a1c.css"></noscript>

Critical CSS is a maintenance surface, so prefer build-time extraction over hand-maintained copies.

Script loading has precise semantics

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

defer downloads without blocking HTML parsing and executes after parsing in document order. async downloads without blocking and executes whenever it arrives, potentially before parsing completes or before dependencies exist. Neither means 'free.' Both still cost network, CPU, memory, and main-thread execution.

Application boot order and dependency expectations often make defer or module loading the correct behavior.

Server streaming changes the shape of waiting

A server that buffers the entire response makes the browser wait for the slowest backend call before seeing even the document head. Streaming can send the shell early:

<head>
  <link rel="preload" as="image" href="/hero.avif" imagesrcset="/hero-800.avif 800w, /hero-1600.avif 1600w" imagesizes="100vw">
  <link rel="stylesheet" href="/assets/app.8f3a1c.css">
</head>

The earlier the browser sees critical metadata, the earlier it can schedule CSS, fonts, and images. Streaming does not fix a slow backend; it overlaps backend latency with client discovery and parsing.

Reserve geometry before content arrives

Layout depends on dimensions. Images without dimensions, embeds without reserved boxes, and ads injected into flow create layout work and CLS:

<img src="/images/chart-1200.webp" width="1200" height="675" alt="Request latency by region">

Field notes

  • 'CSS is small' is not a defense when it is on every first render and discovered late.
  • Preloading everything destroys prioritization. Preload only resources that are both critical and otherwise discovered late.
  • Fonts can block text rendering even when the layout is otherwise ready; font strategy deserves its own decision rather than an accidental default.
  • Measure after removing blockers. Some 'optimizations' merely move work later while total user experience remains unchanged.

Was this lesson helpful?

Sign in to rate