All writing

Web performance · Notes from DevTools

Core Web Vitals, the way I learned it

All I knew about Core Web Vitals was the interview theory: LCP, INP and CLS, good for SEO and a faster page. This time I tried them out practically, just for fun, and guess what, it turned out super fun. Here’s how I learned each one, piece by piece, to convince my inner self.

Published
Audited on
My portfolio site
Read
~16 minutes

On a high level, this is what the Core Web Vitals are.

Three questions a visitor asks without thinking. Each vital puts a number on one.

Maybe these don’t justify anything practically yet, right? So let’s try to understand them from the fundamentals.

What happens when a page loads?

Say I open my own site, mariappan.netlify.app. Before anything shows up, the request goes through five stages.

Five stages before the first pixel. The first three are the price of a new connection.

What gets fetched first?

The HTML document is always the first thing fetched. It’s parsed as it streams in, so content near the top can appear early, before the whole file has arrived.

Chrome’s Network panel for my portfolio home, cache disabled. The first row, mariappan.netlify.app of type document with initiator Other, is highlighted. Below it come stylesheets, images, a script, an SVG and fonts, each with an initiator pointing back to the index or to the font stylesheet.
My portfolio home, cache off. The document leads, and the other 22 requests follow from it.

How does the browser find everything else?

As the parser reads the HTML, it finds other files (stylesheets, images, scripts) and fetches them. Some of those files point to more files. That’s the discovery chain, and the Initiator tab draws it.

The Initiator tab’s request initiator chain for the document. Under mariappan.netlify.app, the Google Fonts stylesheet opens into six font files, highlighted as found inside the CSS. Further down, three portrait images sit directly under the document, highlighted as found in the HTML.
Fonts sit two hops deep. The HTML asks for a stylesheet, and only the stylesheet knows about the fonts.
Each hop waits for the file before it. The deeper a file sits, the later it can start.

What happens inside one request?

Open the Timing tab on the document, and every stage gets a number.

Now reload the page. A few stages disappear, because the browser reuses the connection it already has. Open the page fresh (a new Incognito window is the surest way), and they all come back.

New tab · fresh
Timing tab for the document on a fresh connection: queueing 13.05 ms, stalled 1.50 ms, DNS lookup 11 µs, initial connection 187.84 ms, SSL 95.68 ms, request sent 0.22 ms, waiting for server response 733.37 ms, content download 2.98 ms, 939.19 ms in total. Everything above content download is boxed as TTFB, about 936 ms.
Reload · reused
Timing tab for the same document after a reload: queueing 0.82 ms, stalled 3.99 ms, no DNS, initial connection or SSL rows, request sent 0.51 ms, waiting for server response 96.78 ms, content download 91.83 ms, 193.94 ms in total. Everything above content download is boxed as TTFB, about 102 ms.
Same request, twice. On a reload there are no DNS, connection or SSL rows: the line was already open.

So, what’s TTFB?

Time to first byte. Everything before content download counts towards it: the queue, the connection, and the wait for the server.

Everything before the download is TTFB. Roughly: total minus content download.
  • TTFB ≈ total − content download. On the fresh run, 939.19 − 2.98 ≈ 936 ms.
  • No DNS or connection rows? The connection was reused. Test fresh to see the real cost.
  • “Waiting for server response” alone isn’t TTFB. It’s only the server’s share.

Noticed the three labels at the bottom?

They sit at the bottom of the Network panel, and two of them also draw a line across the waterfall.

The same Network panel, with the blue and red vertical lines on the waterfall boxed, and the summary bar at the bottom boxed: Finish 4.65 s, DOMContentLoaded 2.93 s in blue, and Load in red, cut off at the edge.
Finish, DOMContentLoaded (the blue line) and Load (the red line).
Parsed, loaded, finished: three different moments, and none of them is “the user sees it”.

How do pixels get painted?

Downloaded ≠ painted.

A file can be fully downloaded and still not be on screen. That gap is the render delay, and it’s where a lot of slow pages hide.

What happens when the parser finds CSS?

It keeps reading. Only the painting waits, because every element needs to know what the CSS does to it.

And when it finds a script?

It stops right there, until the script downloads and runs. Why do you think so?

Think for a second, then tap

Because a script can change the page itself. It can add, remove or rewrite the very elements the parser is about to read, so the parser has to wait and see.

CSS stops the painter. Scripts stop the reader.

That’s why people care so much about defer, async and where a script sits.

Normal, async or defer?

Look at the gaps in the green bar. That’s the page waiting on your script.

Module scripts (type="module", what Vite and Astro output) behave like defer by default.

Try it: watch it paint

Four experiments, one page. Press play and watch what shows up, and when.

index.html

<head>
</head>
<body>
  <h1>Top of the page</h1>
  <p>I am above the script.</p>
  <script src="slow.js"></script>3 s
  <p>I am below the script.</p>
  <img src="photo.jpg" alt="">
</body>

localhost

  • ParserBlocked by the script
  • PainterPainting
  • ImageDownloaded, not painted
2.0 s

The parser stops at the script for 3 s, so only the text above it paints. The image finished downloading at 1.5 s, but it can’t paint until the parser reaches it. That gap is render delay.

Pick an experiment and press play. Watch what the screen shows, and when.

LCP: when the biggest thing paints

Navigation start → the biggest visible thing is painted.

Only what’s visible in the viewport counts.

Which element is the LCP?

On desktop, it’s my portrait. On a phone, the portrait drops below the fold and a paragraph takes over. The Performance tab’s Live metrics shows which.

Desktop
My portfolio home on desktop beside the Performance tab’s Live metrics. The portrait in the hero is outlined as the LCP element, an img of 287 by 368 pixels, and the LCP card reads 2.47 s, good, LCP element img.
Mobile
My portfolio home in a 393 by 852 phone viewport beside Live metrics. The intro paragraph, p.hero-lede, is outlined as the LCP element, the portrait sits below the fold, and the LCP card reads 1.14 s, good.
Same page, two LCP elements. The portrait on desktop, a paragraph on a phone.

What is the LCP number made of?

The interesting part: hover the value, and DevTools splits it into four parts we’ve already met.

Same page, two LCP elements, two different problems. Find the biggest part before fixing anything.
The fix depends on the biggest part, and the biggest part depends on the device.

Are live metrics enough?

They’re a quick look. The proper audit is record and reload.

  1. 1Throttle network and CPU
  2. 2Record and reload
  3. 3Read the insights
  • LCP breakdown
  • Render-blocking requests
  • Ways to improve
  • Ask AI, added recently :)

What if I click early?

LCP stops at the first click, tap or key press. I found out by accident: I clicked a social link early, and LCP froze at a better number than the page deserved.

Early clickers make field LCP look better than reality.

So what was wrong on my portfolio?

  • missingsrcset

    Phones downloaded desktop-sized portraits.

  • there, butfetchpriority="high"

    Only speeds the download. Can’t fix discovery or render delay.

  • there, butloading="lazy"

    Skips only far-off images. My stacked carousel was all “in view”.

Can I read it in code?

Yes, through PerformanceObserver.

Log the LCP time and element
new PerformanceObserver((list) => {  const entry = list.getEntries().at(-1);  // the last candidate wins  console.log(Math.round(entry.startTime), entry.element);}).observe({ type: 'largest-contentful-paint', buffered: true });

CLS: when the page moves on its own

How much visible content moves without the user causing it.

Is it one shift or many?

Many. Shifts come in bursts (session windows), and CLS is the worst burst, not the total.

Shifts come in bursts. CLS keeps only the worst one.

How is a shift scored?

Impact fraction × distance fraction: how much of the screen moved, times how far.

Big things moving far score high. Small things nudging a little barely register.

So CLS has no unit, just a score. Here’s my portfolio’s.

Two shifts, 0.0003 and 0.0047, in one burst. Together 0.005, shown rounded as 0.01.

The CLS card in Live metrics for my portfolio on desktop: 0.01, labelled no unit, just a score, with the worst cluster reading 2 shifts. Below, the Layout shifts tab lists two shifts: score 0.0003 for span.rotator, and score 0.0047 for ul.nav-links, #text, svg.doodle.annot and two li elements. A label adds them: 0.0003 plus 0.0047 is about 0.01.
Two small shifts in one burst. Together, my CLS.

What usually causes shifts?

Usually something arrives late, or grows, and pushes everything under it.

Something arrives late, or grows, and everything under it moves. Hold the space up front.

So the fix is always the same: hold the space up front.

What about a Load more button?

Results that arrive 1 s after the click are outside the 500 ms window, so they count. The fix: a skeleton of the right size, straight away.

Without a skeleton

Load more footer · links

Waiting for a click

With a skeleton

Load more footer · links

Waiting for a click

The skeleton shows inside the grace window, so it’s free. The results then fill space that’s already held.

INP: the main thread and one busy cashier

You must be feeling the weight of all these terms by now. So let’s keep this one light. Picture a café with a single cashier.

One cashier, one job at a time. Every tap pays all three.

That cashier is the main thread. It runs all the JavaScript on the page, one job at a time, because JavaScript is single-threaded.

What if I tap while it’s busy?

Your tap doesn’t interrupt. It joins a queue, and the event loop picks it up when the thread is free. Try it.

tap while the thread is busy, then while it’s free

Main thread

Your tap’s timing shows up here.

Same button, same code. Only the moment you tap changes how long you wait.

The event loop deserves a post of its own. For the full picture, watch this talk on it.

How did my portfolio do?

Live metrics lists every interaction with its three parts. Flipping the portrait card was my slowest, so it set the INP.

My portfolio home beside Live metrics. The INP card reads 24 ms, good, interaction pointer. Below, the Interactions tab lists three pointer interactions: 8 ms and 16 ms on section.wrap, and 24 ms on the portrait img, marked INP and expanded: input delay 4, processing duration 0, presentation delay 20. The portrait image on the page is outlined.
Three taps: 8, 16 and 24 ms. INP is the slowest one: 4 ms wait, 0 ms work, 20 ms show.

Lab vs field: which number counts?

Everything so far was lab data: one load, my machine, my network. Great for debugging.

The real pass mark comes from real visitors, at the 75th percentile: 75% of visits must be good, on all three.

The score is the visit three-quarters of the way along. 75% of real visits must be good.

So how do we measure real visits?

Debug in the lab. Judge by the field.

For your own real-user monitoring (RUM), there’s the web-vitals library.

Report all three from real visits
import { onLCP, onINP, onCLS } from 'web-vitals';// each fires with the metric's value, rating and attributiononLCP(sendToAnalytics);onINP(sendToAnalytics);onCLS(sendToAnalytics);

Why does all this matter?

Because they’re how a page feels to the person using it: does it show up, does it answer, does it stay still.

That’s the way I learned it: DevTools open, on my own site, one metric at a time. Pick a page you own and try the same.

Back to all writing