Skip to content

Lesson 11 of 13 · 21m

What Users Actually Wait For

The render-blocking critical path, LCP/CLS/INP as the metrics users feel, `srcset` and `fetchpriority` for images, and `font-display: swap` done without layout shift.

Users don't experience your app; they experience its load. Google published the canonical experiment data in 2006 — an extra 500ms of latency cut traffic by 20% — and Amazon's own measurements found roughly 1% of sales lost per 100ms. Everything below is why pages are actually slow, in the order the browser hits it.

The critical path is shorter than you think

HTML is render-blocking by nature. CSS is render-blocking by design — the browser will not paint until the CSSOM exists, because painting early shows unstyled content. A plain <script src> is parser-blocking: the parser halts, downloads, executes, resumes — a legacy of document.write, which can rewrite the stream mid-parse. (Chrome has refused to run document.write-injected scripts on slow connections since late 2016.)

That is the whole model: HTML, CSS, and JS compete for the same startup budget. The metrics measure what users see of it — LCP (largest contentful paint; good is 2.5s or under — usually your hero image or H1), CLS (layout shift; good is 0.1 or under — things jumping while you read), and INP (interaction latency; it replaced FID as a Core Web Vital in March 2024 — good is 200ms or under).

Images: the LCP is usually a picture

<img src="hero-800.jpg"
     srcset="hero-400.jpg 400w, hero-800.jpg 800w, hero-1600.jpg 1600w"
     sizes="(max-width: 640px) 100vw, 800px"
     width="800" height="450"
     fetchpriority="high" decoding="async" alt="…">
  • srcset/sizes — the browser picks the file by layout width and device pixel ratio. 400w means "this file is 400 pixels wide"; sizes tells it the slot. A 3x phone on a 390px screen wants ~1200 image pixels, not your 2400px desktop hero.
  • width/height — since 2020 browsers compute the aspect ratio from these attributes and reserve the box before the image loads. This is the single biggest CLS fix that exists; most layout shift is images without dimensions.
  • loading="lazy" — defers offscreen images; shipped in Chrome 76 back in 2019 and everywhere since. The classic footgun: lazy-loading the hero image hurts LCP — it's the one image you want eager. The correct tool there is fetchpriority="high" (Chrome 102, Safari 17.2, Firefox 132).
  • <picture> — art direction and format fallback: AVIF (Chrome 85, Firefox 93, Safari 16.4 — March 2023 was the holdout), then WebP, then JPEG.

Fonts swap; the trick is keeping the layout still

font-display: swap inside @font-face shows fallback text immediately and swaps when the woff2 arrives — the alternative, block, is the dreaded FOIT: up to three seconds of invisible text. The swap itself causes CLS unless you match metrics: size-adjust, ascent-override, descent-override, line-gap-override (Chrome 87+) reshape the fallback so the swap doesn't move lines.

Preload the font — <link rel="preload" as="font" type="font/woff2" crossorigin> — and note crossorigin is required even for same-origin files: fonts fetch in CORS mode, so an uncredentialed preload never matches the font request's cache entry.

For long pages: content-visibility and friends

content-visibility: auto on below-the-fold sections skips their rendering entirely until they approach the viewport — a real LCP and INP win on long docs and feeds, priced at an occasional scrollbar recalculation. Pair it with contain-intrinsic-size so the browser can estimate the section's height before it renders.

The resource-hint trio gets confused constantly: preload fetches a needed resource for this page now, prefetch warms the cache for the next navigation at idle, preconnect only opens the connection — DNS plus TLS handshake — ahead of time. Using preload where preconnect meant "warm the CDN" wastes bandwidth on assets the page may not need.

Try it yourself

const vw = 390, dpr = 3;
console.log("Needed pixels:", vw * dpr, "-> pick the 1600w file");

The practice

width and height on every <img>, lazy below the fold only, fetchpriority="high" on the LCP image, font-display: swap plus metric overrides, AVIF/WebP with a JPEG fallback. Then measure in the field — lab scores are a hypothesis; real-user metrics are the answer.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.