The story so far. Maya, Nina and Omar ran TinyTickets, a ticket site for many organizers. For the stadium sale, they had grown it from one server into a system that held 60,000 buyers at 10:00. Their dashboards watched the servers, and every server stayed healthy. Nobody watched what happened inside the buyers’ phones.
The whole story, from the first club show, is on the story page.
Two days after the stadium sale, Leo forwarded eleven messages from buyers. “The seat map froze on my phone,” one said. Maya opened the dashboards from sale day, and every graph had stayed green. On her laptop, the seat map opened at once, and a tap turned a seat orange without a pause.
Maya, Leo and TinyTickets are invented, and so are the numbers in their story.
This module is about measuring a slow page before you change it. You’ll see why a page that’s fast on your laptop can be slow for the people who use it. You’ll learn to measure Core Web Vitals from real buyers and to reproduce them in a lab. Every later module starts from the numbers this one teaches you to collect.
After this module, you can:
- tell field data from lab data, and say which one decides what you fix
- read LCP, INP and CLS at the 75th percentile of page loads and rate them against the thresholds
- find a page’s public field data in CrUX, and name the visitors CrUX leaves out
- set CPU and network throttling so your laptop shows the field’s symptom, and name what throttling can’t copy
- send LCP, INP and CLS from your visitors’ browsers to your own endpoint, and compute the 75th percentile from it
What buyers saw, and what the servers missed
Leo’s eleven messages described three different problems. Some buyers waited a long time for the map to appear. Some tapped a seat and nothing happened for a second or more. A few said the map jumped down the screen as they were about to tap.
None of this showed on the dashboards. Figure 1 shows why. The dashboards measure requests from the moment they reach the CDN until the response leaves. So everything the phone does after the response arrives happens outside that view.
(Buyers' phones) --> [CDN] --> [TinyTickets servers] --> [[PostgreSQL]]
| \___________ watched by the dashboards ___________/
|
+-- after the response arrives, inside the phone:
download the files, run JavaScript, lay out the page,
paint it, answer taps watched by nobody
Legend: (people) [program or server] [[stored data]] --> request
Figure 1: the dashboards end where the phone’s work begins.
Maya needed field data from the phones. Field data is measurements taken in real visitors’ browsers, on their own devices and networks. Her server metrics were field data too, but for the servers.
For the browser side, one source already existed. The Chrome User Experience Report (CrUX) is a public dataset that Google builds from page loads in Chrome, for users who opted in to sharing usage statistics (CrUX methodology).
The seat map page had enough Chrome visitors on sale day to appear in CrUX. Maya looked up the 28-day window that held the sale. For phones, it showed three numbers, each at the 75th percentile:
| Metric | Phones, 75th percentile |
|---|---|
| LCP | 4.8 s |
| INP | 1,200 ms |
| CLS | 0.25 |
Pause and predict. On Maya’s laptop, the seat map looks fine. Which of the buyers’ three problems do you expect her laptop to miss completely, and why? Write your guess down; the lab run in the next sections answers it.
Three numbers for three complaints
Each of the three numbers measures one of the buyers’ complaints.
- “The map took forever to appear.” Largest Contentful Paint (LCP) is the time from the start of the load until the largest image or text on screen is painted.
- “I tapped and nothing happened.” Interaction to Next Paint (INP) is the time from a tap, click or key press until the next frame appears. It comes from about the slowest interaction of the visit.
- “The map jumped.” Cumulative Layout Shift (CLS) is a score for how far visible content moves without the user asking it to.
The Core Web Vitals are these three metrics, the ones Google’s Web Vitals program asks every site to measure, each with a fixed “good” and “poor” threshold (web.dev, Web Vitals). A page passes only if all three are good at the 75th percentile, with phones and desktops measured separately.
Figure 2 lists the thresholds, read on web.dev on 2026-11-18, next to TinyTickets’ phone numbers.
| Metric | Good | Needs improvement | Poor | TinyTickets, phones, p75 |
|---|---|---|---|---|
| LCP | 2.5 s or less | 2.5 s to 4.0 s | over 4.0 s | 4.8 s, poor |
| INP | 200 ms or less | 200 ms to 500 ms | over 500 ms | 1,200 ms, poor |
| CLS | 0.1 or less | 0.1 to 0.25 | over 0.25 | 0.25, needs improvement |
Figure 2: on phones, the seat map is poor on two metrics and one step from poor on the third. Sources: LCP, INP, CLS.
Maya knew percentiles from server latency. But here the unit changes. A server’s p75 is taken over requests, and a Core Web Vitals p75 over page loads. Each visit gives one LCP, one CLS and one INP, and the 75th percentile is taken over those visits.
The 75th percentile is a choice. Google picked it so that a passing page is good for most visits, while a few slow outliers can’t move the number on their own. If a page has 100 visits, the p95 changes after 5 bad samples, but the p75 needs 25 (web.dev, defining the thresholds). The thresholds are the same for phones and desktops, and most were set by what phones can reach.
Rule: A Core Web Vitals number is the 75th percentile of page loads, for one device class, and a page passes only when all three are good.
Run the seat map on your laptop
The rest of this module uses a small copy of the TinyTickets front end. It has a Node.js server with no framework and the seat map page with all 60,000 stadium seats. A fake analytics script comes from a second address, as a real third party would. You’ll need Node.js. The current long-term-support release is 26, and the code also runs on 22.
Make a folder, and mark it as using ES modules, so Node.js accepts import:
mkdir tinytickets-lab && cd tinytickets-lab && npm init -y && npm pkg set type=module
Put these files in it:
tinytickets-lab/
package.json
server.js
public/
seats.html
seats.js
styles.css
stadium.jpg
third-party/
analytics.js
stadium.jpg is a 1600 × 900 px plan of the stadium, 704 KB. Take it from the course repository, folder module-01/public/, or use any JPEG of about that size.
Here’s server.js. It serves public/ on port 8080 and third-party/ on port 8081. A ?delay= query string holds any response back, so later modules can make one file slow on purpose.
import { createServer } from 'node:http';
import { readFile } from 'node:fs/promises';
import { extname, join } from 'node:path';
import { setTimeout as sleep } from 'node:timers/promises';
const TYPES = {
'.html': 'text/html; charset=utf-8',
'.js': 'text/javascript; charset=utf-8',
'.css': 'text/css; charset=utf-8',
'.jpg': 'image/jpeg',
};
// Serves the files in one folder. ?delay=800 holds a response back for 800 ms.
async function serveFile(req, res, folder) {
const url = new URL(req.url, 'http://localhost');
await sleep(Number(url.searchParams.get('delay')) || 0);
const path = join(folder, url.pathname === '/' ? 'seats.html' : url.pathname);
if (!path.startsWith(folder)) return res.writeHead(403).end();
try {
const body = await readFile(path);
res.writeHead(200, { 'Content-Type': TYPES[extname(path)] ?? 'application/octet-stream' });
res.end(body);
} catch {
res.writeHead(404).end('Not found');
}
}
const app = join(import.meta.dirname, 'public');
const thirdParty = join(import.meta.dirname, 'third-party');
createServer((req, res) => serveFile(req, res, app)).listen(8080);
createServer((req, res) => serveFile(req, res, thirdParty)).listen(8081);
console.log('TinyTickets on http://localhost:8080, third parties on http://127.0.0.1:8081');
The page loads from localhost, and the analytics script from 127.0.0.1. Lighthouse is Google’s automated page test, which runs inside DevTools and on Google’s servers. DevTools and Lighthouse ignore the port when they decide what counts as a third party, so a second port on localhost would look like the site itself. But the two host names are two different sites to the browser.
public/seats.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stadium seat map - TinyTickets</title>
<link rel="stylesheet" href="/styles.css">
<script src="http://127.0.0.1:8081/analytics.js"></script>
</head>
<body>
<header>TinyTickets</header>
<main>
<h1>Pick your seats</h1>
<img src="/stadium.jpg" alt="Plan of the stadium, with the stage at the north end">
<p id="status">Loading seats...</p>
<div id="map"></div>
</main>
<script src="/seats.js"></script>
</body>
</html>
public/styles.css draws each seat as a 6 px square in a grid of 200 columns, inside a box that scrolls:
body { margin: 0; font: 16px/1.5 system-ui, sans-serif; color: #1d1d1f; }
header { padding: 8px 16px; background: #1d1d1f; color: #fff; font-weight: 700; }
main { padding: 0 16px; }
img { display: block; width: 100%; }
#map {
display: grid;
grid-template-columns: repeat(200, 6px);
gap: 1px;
height: 60vh;
overflow: auto;
}
.seat { width: 6px; height: 6px; background: #3a7bd5; }
.seat.sold { background: #c7c7cc; }
.seat.picked { background: #e8590c; }
public/seats.js builds one element per seat, then keeps every element up to date with the seat list:
const SEAT_COUNT = 60000;
const map = document.getElementById('map');
const status = document.getElementById('status');
// About 6 in 10 seats are already sold. The pattern is fixed, so every run is the same.
const seats = Array.from({ length: SEAT_COUNT }, (_, i) => ({
id: i,
row: Math.floor(i / 200) + 1,
number: (i % 200) + 1,
price: i < 20000 ? 95 : 60,
sold: (i * 7919) % 10 < 6,
}));
const picked = new Set();
map.innerHTML = '<span class="seat"></span>'.repeat(SEAT_COUNT);
const elements = [...map.children];
// Brings every seat element up to date with the seat list.
function render() {
let free = 0;
for (const seat of seats) {
const state = seat.sold ? 'sold' : picked.has(seat.id) ? 'picked' : 'free';
const label = `Row ${seat.row}, seat ${seat.number}, $${seat.price}, ${state}`;
const element = elements[seat.id];
element.className = `seat ${state}`;
element.title = label;
element.setAttribute('aria-label', label);
element.setAttribute('aria-disabled', seat.sold);
element.setAttribute('aria-pressed', state === 'picked');
if (state === 'free') free++;
}
status.textContent = `${free} seats free, ${picked.size} picked`;
}
map.addEventListener('click', (event) => {
const id = elements.indexOf(event.target);
if (id === -1 || seats[id].sold) return;
picked.has(id) ? picked.delete(id) : picked.add(id);
render();
});
render();
third-party/analytics.js stands in for the analytics script that runs on every TinyTickets page:
// A fake analytics script. It is served from a second origin, like a real one.
window.analytics = { page: location.pathname, loadedAt: Math.round(performance.now()) };
Start the server:
node server.js
TinyTickets on http://localhost:8080, third parties on http://127.0.0.1:8081
Open http://localhost:8080/seats.html in Chrome. To see what the browser measured, you’ll need a way to read its timings from the page.
A PerformanceObserver is a browser object that calls your function each time the browser records a timing entry of one type, such as a paint (MDN). With buffered: true, it also receives the entries recorded before you created it. Open DevTools, go to the Console, and paste this snippet:
function watch(type, describe) {
new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
const text = describe(entry);
if (text) console.log(type, text);
}
}).observe({ type, buffered: true, durationThreshold: 16 });
}
const ms = (n) => `${Math.round(n)} ms`;
watch('largest-contentful-paint', (e) => `${ms(e.startTime)} ${e.url || e.element?.tagName}`);
watch('layout-shift', (e) => `${e.value.toFixed(3)} at ${ms(e.startTime)}, moved ${e.sources.map((s) => s.node?.id || s.node?.nodeName).join(' ')}`);
watch('event', (e) => e.interactionId && `${e.name} ${e.duration} ms, handlers ${ms(e.processingEnd - e.processingStart)}`);
It prints each LCP candidate, each layout shift and the elements it moved, and each input event that belongs to an interaction, with the time its handlers ran. Then scroll to the map and tap one blue seat.
Here’s one run in headless Chrome 157 on a 2019 laptop (Intel Core i7-9750H), in a 1350 × 940 window, with the cache off. The tap was a mouse click sent through the DevTools Protocol. Your numbers will differ.
largest-contentful-paint 628 ms http://localhost:8080/stadium.jpg
event pointerdown 160 ms, handlers 0 ms
event pointerup 152 ms, handlers 0 ms
event click 152 ms, handlers 76 ms
LCP was 628 ms, and its element was the stadium image. The tap took 160 ms from the press to the next frame, under the 200 ms threshold. One tap fires several events, and its time is the longest of them.
There’s no layout-shift line at all. That answers the prediction: in this run, the laptop missed the jumping map completely. On localhost, the image arrived in under 30 ms, before the browser first painted the page, so nothing on screen ever moved.
But the shift depends on timing. In a later laptop run of the same page, the browser painted the heading at 72 ms, before it knew the image’s size, and the snippet printed layout-shift 0.364 at 656 ms, moved map status. A problem that appears in some runs and not others is one more reason to read many page loads, not one.
Make the laptop behave like a phone
Lab data is a measurement taken in a setup you control: one device, one network, one cache state, and you decide when to tap. It’s repeatable, and it lets you look inside the page. But your laptop isn’t your buyers’ phone. A laptop’s processor runs the same JavaScript several times faster than a mid-range phone, and localhost has no network delay at all.
Throttling is DevTools slowing your own machine on purpose, to imitate a slower device or network. It has two parts:
- CPU throttling pauses the page’s main thread for part of the time. At 4x, the main thread runs about a quarter of the time. It doesn’t slow the GPU process, the disk or memory, and it doesn’t copy a phone’s heat limits (Chrome DevTools blog, 2025).
- Network throttling adds a fixed wait to each request and caps the download and upload speed. The “Slow 4G” preset targets a 150 ms round trip and 1.6 Mbps down. In the DevTools source, it adds 562.5 ms to each request (150 × 3.75) and caps the speed at 90% of the target.
Figure 3 shows what each part changes and what it leaves alone.
Part of the work Laptop, no throttling Throttled
------------------------------- ---------------------- ----------------------------
Main thread: JavaScript, style, full speed paused part of the time
layout (4x: runs 1/4 of the time)
GPU and compositing full speed full speed, not touched
Network localhost, about 0 ms +562.5 ms per request,
1.44 Mbps down (Slow 4G)
Disk, memory, heat the laptop's the laptop's, not touched
Figure 3: throttling slows the main thread and the network, and nothing else.
DevTools has two combined presets. “Mid-tier mobile” is Slow 4G with 4x CPU, the same setting Lighthouse uses for its phone runs. “Low-tier mobile” is the slower “3G” network preset with 6x CPU.
Since Chrome 134 (2025), DevTools can also calibrate the CPU presets. It runs a short benchmark on your machine and picks the slowdown that matches a mid-tier and a low-tier phone (Chrome DevTools blog).
The runs below keep Slow 4G and change only the CPU, from 4x to 6x, so that one thing changes at a time.
First, in DevTools, open the Performance panel and its capture settings (the gear icon). Set CPU to “4x slowdown” and Network to “Slow 4G”. Then open the device toolbar, choose Responsive, 412 × 823, and set the device type to “Desktop (touch)”.
The device type matters for CLS. In headless runs of this lab, mobile emulation made Chrome mark the image’s shift as following recent input, and the library this module adds later left it out of CLS. But a touch-enabled viewport without mobile emulation kept it.
Reload with the cache off (in the Network panel, check “Disable cache”), paste the snippet again, and tap a seat. Then repeat with CPU at “6x slowdown”. Here’s one run of each, on the same laptop, 412 × 823, Slow 4G. First 4x:
largest-contentful-paint 1264 ms H1
largest-contentful-paint 5316 ms http://localhost:8080/stadium.jpg
layout-shift 0.190 at 3396 ms, moved map status
event click 552 ms, handlers 262 ms
Then 6x:
largest-contentful-paint 1312 ms H1
largest-contentful-paint 6328 ms http://localhost:8080/stadium.jpg
layout-shift 0.190 at 5431 ms, moved map status
event click 768 ms, handlers 373 ms
The jumping map is back, and the tap is three to five times slower. LCP moved from the heading at about 1.3 s to the image at 5.3 to 6.3 s.
| Profile | LCP | Layout shift | Tap |
|---|---|---|---|
| Laptop, no throttling | 0.63 s | none | 160 ms |
| 412 × 823, Slow 4G, 4x CPU | 5.32 s | 0.190 | 552 ms |
| 412 × 823, Slow 4G, 6x CPU | 6.33 s | 0.190 | 768 ms |
| Field, phones, p75 (CrUX) | 4.8 s | 0.25 | 1,200 ms |
The 6x profile came closest on the tap. That fits a 75th percentile, because a quarter of the buyers’ page loads were slower than it, so it describes slow phones.
The lab LCP is worse than the field’s, partly because the lab always loads with an empty cache and the field doesn’t. No lab profile matches the field exactly, but it only has to show the same symptom.
Rule: Change the lab until it shows the field’s symptom, then measure from there; never tune it until it matches a number.
How the browser measures each number
The snippet printed raw entries. Each Core Web Vital is a rule applied to those entries, and the rule explains most of the gaps between lab and field.
LCP: the last large paint before the user acts
During the load, the browser reports a new largest-contentful-paint entry each time it paints an element larger than the previous one. That’s why the 4x run printed two lines: the h1 at 1,264 ms, then the image at 5,316 ms. The last entry before the user acts is the LCP.
Only some elements count: images (including CSS background images), the poster or first frame of a video, and block elements with text. The browser counts only the part of the element inside the viewport, and an image upscaled beyond its natural size counts at its natural size. It stops reporting candidates as soon as the user taps, scrolls or presses a key (web.dev, LCP). web-vitals stops on taps and key presses but not on scrolls, because a script can scroll the page too.
Chrome’s LCP time runs until the frame is shown on screen. Firefox and Safari stop a few milliseconds earlier, when the frame is painted. Since Chrome 145, the entry has a paintTime field so you can compare like with like (web.dev, 2025-12-17).
INP: about the slowest interaction of the visit
An interaction is one tap, click or key press; hover, scroll and zoom aren’t interactions. Each one fires several events, such as pointerdown, pointerup and click. The browser times each one from the input until the next frame is presented, rounded to 8 ms. All the events of one interaction share an interactionId, which is why the snippet filters on it (Event Timing specification).
INP takes the slowest interaction of the visit, with one exception: for every 50 interactions, the single slowest one is ignored. So a buyer who picks many seats isn’t judged by one unlucky tap. Figure 4 shows two visits.
Visit A: 3 taps, sorted slowest first
760 410 140 ms
^ INP = 760 ms (fewer than 50 interactions: the slowest counts)
Visit B: 120 taps, sorted slowest first
1,180 960 820 790 ... 40 ms
^ ^ ^ INP = 820 ms
ignored ignored (120 / 50 = 2, so the 2 slowest are ignored)
Figure 4: INP is the slowest interaction, minus one for every 50 interactions.
A visit with no tap, click or key press has no INP at all. A lab tool that loads a page and never taps it can’t measure INP for the same reason.
CLS: the largest group of shifts
A layout shift happens when a visible element’s start position moves between two frames without the user causing it. Its score is the share of the viewport the moving elements cover, times the distance they moved as a share of the viewport’s larger side. In the 6x run, the map and the status line moved down by the height of the image, and the shift scored 0.190 (web.dev, CLS).
The browser leaves out shifts within 500 ms of a tap, click or key press, because the user expects the page to react. Movement done with a CSS transform is never a shift. The entry’s sources list names up to five elements that moved, largest first.
CLS groups shifts that come less than 1 second apart, with each group at most 5 seconds long. CLS is the sum of the largest group, not the total of all shifts. Figure 5 shows three shifts that form two groups.
time (s) 0 1 2 3
| | | |
shifts *0.05 *0.10 *0.08
0.2 s 0.9 s 2.5 s
groups [ group 1: 0.05 + 0.10 = 0.15 ]
[ group 2: 0.08 ]
CLS = 0.15, the largest group. The total, 0.23, is not used.
Figure 5: a gap of 1 second or more starts a new group of shifts.
Field CLS keeps counting for the whole life of the page, including shifts after the load and after scrolling. But lab CLS in tools like Lighthouse counts only shifts during the load, in the first screen.
Why lab and field disagree
Figure 6 shows where each kind of number comes from.
Field data:
(Buyers) --> [their phones and networks] --> [CrUX, or your endpoint]
thousands of page loads --> p75 per device class
Lab data:
(You) -----> [your laptop, one profile] --> one page load, one number
Figure 6: field data is many page loads summarized; lab data is one load you control.
The numbers differ for reasons you can name (web.dev, lab and field data):
- Devices and networks. The field has every phone and network your buyers use; the lab has one of each.
- Cache. The lab usually loads with an empty cache. Returning buyers have the CSS and images already.
- Interactions. Real buyers tap at moments the lab never picks. Field LCP can be faster because a tap ends it early.
- Time. Field CLS includes shifts long after the load; lab CLS stops at the end of the load.
- Back and forward. A page restored from the browser’s back/forward cache counts in the field, and lab tools never do it. Module 4 covers this cache.
When they disagree, the field decides what to fix, and the lab tells you why.
What changed since 2021
- 2021, Chrome 91. CLS became the largest group of shifts. Before, it added up every shift over the life of the page, so long-lived pages scored worse (web.dev, evolving CLS).
- 2024-03-12. INP replaced First Input Delay as a Core Web Vital. First Input Delay timed only the wait before the first interaction’s handlers started (web.dev, INP launch).
- May 2024. DevTools renamed its “Fast 3G” preset to “Slow 4G”, to match Lighthouse (DevTools source,
NetworkManager.ts). - 2025, Chrome 134. DevTools can calibrate CPU throttling to your machine (Chrome DevTools blog).
- 2025-12-12. Safari 26.2 shipped LCP and the event timing that INP needs. Firefox had LCP since version 122 and INP since version 144 (October 2025). LCP and INP now work in all three engines, but CLS still works only in Chromium browsers (web.dev, 2025-12-17).
Follow the numbers to the code
The three numbers point at three places in the seat map. This walkthrough uses the 6x run from above.
- Draw the load. Figure 7 is the page-load timeline, which this course draws in every module. It has one row per file, with time from left to right. TTFB (time to first byte) marks when the HTML’s first byte arrived. First Contentful Paint (FCP) marks the first frame with any text or image. LCP marks the paint of the largest element.
time (s) 0 1 2 3 4 5 6
| | | | | | |
seats.html ======
styles.css ======
analytics.js ======
seats.js ======
stadium.jpg ===================================================
^ TTFB 0.56 s
^ FCP 1.31 s (the h1)
layout shift 0.190 at 5.43 s ^
LCP 6.33 s (stadium.jpg) ^
Figure 7: on the phone profile, the image takes 5 seconds to arrive, and LCP waits for it.
- Compare the laptop. Figure 8 is the same timeline on the laptop, on the same scale. Every file arrived in the first 30 ms, so the image was ready before the first frame.
time (s) 0 1 2 3 4 5 6
| | | | | | |
seats.html =
styles.css =
analytics.js =
seats.js =
stadium.jpg =
^ TTFB 0.003 s
^ FCP and LCP 0.63 s (stadium.jpg)
Figure 8: on the laptop, the network disappears, and so does most of the problem.
- Name the LCP element. The LCP line names
stadium.jpg. The file is 704 KB and 1600 × 900 px, drawn 380 px wide on a 412 px screen. At 1.44 Mbps, 704 KB takes about 3.9 s on its own. But in the run, the download took 4.5 s, from 1.19 s to 5.71 s, because the other files shared the network at the start.
Pause and predict. The image finished at 5.71 s, but LCP is 6.33 s. What could the browser have been doing for those 0.6 s?
Answer
The main thread was busy. The first render() and the layout of 60,000 grid items take a long time at 6x, and the browser can’t paint a frame until that work is done. Module 3 splits LCP into the time to get the file and the time to paint it.
- Name what moved. The shift line says it moved
mapandstatus. Both sit below the image. The<img>tag has nowidthorheight. Until the image’s first bytes arrive, the browser doesn’t know its height, so it lays out the page with a zero-height image. When it learns the real size, it moves everything below. On the laptop, that usually happened before the first paint, so nobody saw it. Module 6 covers this cause.
Pause and predict. The image is 214 px tall on this screen. Why does a shift of 214 px score 0.190 and not more?
Answer
The score is the share of the viewport the moving elements cover, times the distance as a share of the viewport’s larger side. The distance part is 214 / 823, about 0.26. So the area part is 0.190 / 0.26, about 0.73. The map and the status line, before and after the move, cover about three quarters of the viewport, not all of it.
- Find the code behind the tap. The event line says the click took 768 ms and its handlers ran for 373 ms. The page has one click listener, on
#map, inseats.js. It changes the state of one seat and then callsrender().
Pause and predict. One tap changes one seat. How many elements does render() write to, and how many attributes on each?
Answer
All 60,000 seat elements, five attributes each: the class, the title, aria-label, aria-disabled and aria-pressed. That’s 300,000 DOM writes for one changed seat.
- Draw the tap. Figure 9 is the main-thread timeline for that tap, the second figure this course draws in every module. It has one line for the main thread, time from left to right, the 50 ms line for scale and the frame marked. The numbers come from the same run’s event entry and the task timings the browser recorded.
time (ms) 10,940 11,708
| |
tap v
main thread [==== task, 463 ms ====]............| frame
50 ms line [==]
INP parts |----|------------------|-------------|
104 373 handlers 291 to frame
Figure 9: one tap starts a 463 ms task, and the next frame comes 768 ms after the tap.
The tap waited 104 ms before its handlers started, the handlers ran for 373 ms, and the browser needed 291 ms more to produce the frame. A frame every 16.7 ms is what a 60 Hz screen expects. But during this tap, the screen got no new frame for three quarters of a second, which is what buyers called “frozen”. Module 2 opens this task in the Performance panel, and Module 5 explains the three parts.
Rule: Each Core Web Vital names an element or an event; follow that name to the file and the line before you change anything.
The fix: measure every buyer, and keep a phone profile
This module changes no seat map code. The image, the shift and the tap are for Modules 3, 5 and 6. The fix here is to what Maya can see.
CrUX gave her one number per metric for 28 days of Chrome users, without the element names she followed above. But she wanted the same detail from every buyer, on every page, every day.
web-vitals is a small library from the Chrome team that applies the rules above to the raw entries and calls your function with each metric (GitHub). Its attribution build adds, for each metric, the element or event that caused it. The current version is 6.2.3, released 2026-10-05.
Install it and copy its attribution build into public/, so the page can import it with no build step:
npm install web-vitals@6.2.3
mkdir -p public/vendor && cp node_modules/web-vitals/dist/web-vitals.attribution.js public/vendor/
On Windows, use copy with backslashes in place of cp.
Add public/vitals.js:
import { onCLS, onINP, onLCP } from '/vendor/web-vitals.attribution.js';
// One entry per metric id: CLS and INP can report again, and the newest value wins.
const queue = new Map();
const device = matchMedia('(pointer: coarse)').matches ? 'phone' : 'desktop';
function add(metric) {
// Keep the attribution's text and number fields; drop DOM nodes and performance entries.
const attribution = Object.fromEntries(
Object.entries(metric.attribution).filter(([, value]) => typeof value !== 'object'),
);
const script = metric.attribution.longestScript?.entry;
queue.set(metric.id, {
page: location.pathname,
device,
name: metric.name,
value: metric.value,
rating: metric.rating,
id: metric.id,
...attribution,
script: script && `${script.invoker} in ${script.sourceURL}`,
});
}
// "hidden" is the last moment a page can count on, also when a phone closes the tab.
addEventListener('visibilitychange', () => {
if (document.visibilityState !== 'hidden' || queue.size === 0) return;
navigator.sendBeacon('/vitals', JSON.stringify([...queue.values()]));
queue.clear();
});
onCLS(add);
onINP(add);
onLCP(add);
Notice four choices in this file:
- It sends when the page is hidden. CLS and INP keep changing while the buyer uses the page, so the code waits. A phone that closes a tab from the app switcher fires no
unload,beforeunloadorpagehide, but the page does become hidden first (Page Lifecycle API). - It uses
navigator.sendBeacon. The browser queues the POST and sends it even after the page is gone, and the page doesn’t wait for it. The queued data is limited to 64 KiB, andtruemeans “queued”, not “delivered” (MDN). - It keys the queue by
id.web-vitalscan calladdfor the same CLS or INP more than once, each time the page is hidden. Each value carries anidthat stays the same for one page load, so the reader of the data can keep the last one. - It records the device class. Core Web Vitals are judged per device class. A coarse pointer is a touch screen, which is a rough test: a touch-screen laptop counts as a phone.
Load it from seats.html, after the analytics script:
<script type="module" src="/vitals.js"></script>
Then add the endpoint to server.js. Add appendFile to the node:fs/promises import, add this function above const app, and send POST /vitals to it:
import { readFile, appendFile } from 'node:fs/promises';
// Appends each metric a browser sends to vitals.ndjson, one JSON object per line.
async function saveVitals(req, res) {
let body = '';
for await (const chunk of req) {
body += chunk;
if (body.length > 64 * 1024) return res.writeHead(413).end();
}
let metrics;
try {
metrics = JSON.parse(body);
} catch {
return res.writeHead(400).end();
}
if (!Array.isArray(metrics)) return res.writeHead(400).end();
const time = new Date().toISOString();
const lines = metrics.map((metric) => JSON.stringify({ time, ...metric }) + '\n');
await appendFile(join(import.meta.dirname, 'vitals.ndjson'), lines.join(''));
res.writeHead(204).end();
}
createServer((req, res) => {
if (req.method === 'POST' && req.url === '/vitals') return saveVitals(req, res);
return serveFile(req, res, app);
}).listen(8080);
The endpoint accepts data from any browser on the internet. So it limits the body to the 64 KiB a beacon can carry, and it rejects anything that isn’t a JSON array.
Restart the server, load the page in the 6x profile, tap a seat, and switch to another tab. vitals.ndjson gets three lines. Here they are from one run, with the long fractions rounded:
{"time":"2026-11-18T18:05:37.729Z","page":"/seats.html","device":"phone","name":"LCP","value":5328,"rating":"poor","timeToFirstByte":564.9,"resourceLoadDelay":55.7,"resourceLoadDuration":4513.2,"elementRenderDelay":194.2,"target":"html>body>main>img","url":"http://localhost:8080/stadium.jpg"}
{"time":"2026-11-18T18:05:37.729Z","page":"/seats.html","device":"phone","name":"INP","value":752,"rating":"poor","interactionTarget":"#map>span.picked.seat","interactionType":"pointer","inputDelay":76.1,"processingDuration":384.9,"presentationDelay":291,"loadState":"complete","script":"DIV#map.onclick in http://localhost:8080/seats.js"}
{"time":"2026-11-18T18:05:37.729Z","page":"/seats.html","device":"phone","name":"CLS","value":0.18986661529706253,"rating":"needs-improvement","largestShiftTarget":"#map","largestShiftTime":4283.8,"largestShiftValue":0.18986661529706253}
The lines also hold an id and a few more attribution fields, left out here to fit the page.
Each line names the same causes the walkthrough found by hand. The LCP line names the image and shows that 4.5 of its 5.3 seconds went to downloading it. The INP line names the seat, the #map click listener and seats.js. The CLS line names #map.
Figure 10 shows the TinyTickets parts this fix adds.
(Buyers) --> [seat map page]
[web-vitals + vitals.js] NEW
| page hidden: POST /vitals (sendBeacon) NEW
v
[TinyTickets web app] --> [[vitals.ndjson]] NEW
Figure 10: every page load now reports its own three numbers to TinyTickets.
Before and after
The before and after numbers come from the same laptop, the same page and the same reporting code, one run each. The only change is the profile.
| Profile | LCP | INP | CLS |
|---|---|---|---|
| Before: laptop, no throttling | 684 ms, good | 152 ms, good | 0, good |
| After: 412 × 823, Slow 4G, 6x CPU | 5,328 ms, poor | 752 ms, poor | 0.190, needs improvement |
| Field, phones, p75 (CrUX) | 4,800 ms, poor | 1,200 ms, poor | 0.25, needs improvement |
Before, every rating was good, so the laptop showed no problem. After, the lab gives the same three ratings as the field. Adding web-vitals made no difference larger than the noise between runs. The 6x tap took 768 ms without it, and 736 to 760 ms in four runs with it.
What this costs
- Bytes. The attribution build is 15.7 KB, 5.6 KB with gzip. The standard build, without attribution, is 9.0 KB, 3.3 KB with gzip. The lab server sends files uncompressed.
- Requests. One more script per page, and one beacon each time the page is hidden.
- Memory. The attribution build keeps entries until it reports. Versions 6.2.2 and 6.2.3 fixed memory leaks in this code, so stay on a current version.
- Privacy. The lines hold page paths, CSS selectors and script URLs. A query string in a URL can hold a buyer’s data, so strip it before you store it.
- Storage and reading. One file of lines is enough for a lab. In production, you’ll need a place to store millions of lines and a way to query them.
- Coverage.
onCLSworks only in Chromium browsers. The browser APIs don’t see inside iframes, so your numbers can differ from CrUX, which counts iframe content.
The phone profile has a cost too. It’s your laptop with its main thread and network slowed down, not a phone. The GPU, memory and heat behave like the laptop’s, so if your page is GPU-heavy, it can look fine throttled and still be slow on a real phone.
Other ways to get field data
| Option | What you get | Its cost | When to choose it |
|---|---|---|---|
| CrUX alone | p75 for public pages with enough Chrome traffic; no code | Chrome only, 28-day windows, no element names | You want a free check of a public site |
Your own PerformanceObserver code |
No dependency | You rewrite the INP and CLS rules, hidden-page reporting and back/forward restores | You need only one raw entry type |
web-vitals to your endpoint |
Every browser that supports the APIs, with element names | Bytes, storage and the privacy work above | You need per-page, per-release or non-Chrome numbers |
| A hosted monitoring service | Storage, charts and alerts | Money, and buyers’ data on a third party’s servers | You do not want to store and query the data yourself |
In place of sendBeacon, you can use fetch with keepalive: true. It also survives the page, lets you set headers and read the response, and has the same 64 KiB limit (MDN).
Confirming it in the field
Maya shipped vitals.js and the endpoint the same week. Within an hour, vitals.ndjson on the server had lines from buyers browsing next month’s shows, from Chrome on Android and from Safari on iPhones, which CrUX never counts. The lines from iPhones held LCP and INP but no CLS, as expected. The real check would come at the next big sale: her own p75 for phones on the seat map, next to CrUX’s numbers for the same days.
Online tools for this step
Public testing tools load your page from their own servers, so they can test only a public page. Some also keep or publish the results. So never paste a private or internal URL into one. The CrUX tools below don’t load your page at all; they read data Chrome already collected.
PageSpeed Insights shows two things for one URL (about PSI):
- Field: CrUX data for the last 28 days: LCP, INP, CLS and FCP, for phones and desktops, with the pass or fail result. If the URL has too little data, it shows the whole origin; if the origin has too little, it shows none.
- Lab: one Lighthouse run from a Google server in North America, Europe or Asia, emulating a phone on Slow 4G with 4x CPU. It shows no INP, because nobody taps. In its place it shows TBT. Total Blocking Time (TBT) is Lighthouse’s lab number for how long the main thread was too busy to answer input during the load.
- Limits: public URLs only; one simulated lab run; no history. It’s free, and its API recommends an API key.
- When DevTools is better: pages behind a login, pages that aren’t public yet, and any time you need a trace or your own throttling.
CrUX Vis shows CrUX history for an origin or a URL: up to 40 weekly points, each a 28-day window, so neighboring points overlap. You can filter by phone, desktop or tablet (CrUX Vis docs).
- Field only. It’s the tool for “when did this get worse?”, and how Maya found the window that held the sale.
- Limits: no data for sites that aren’t in CrUX, and no custom views. It replaced the CrUX Dashboard, which stopped loading data at the end of November 2025.
- When DevTools is better: for anything that needs a reason, not a trend.
The CrUX API returns the same data as JSON, for scripts and your own dashboards. A request looks like this:
curl -s "https://chromeuxreport.googleapis.com/v1/records:queryRecord?key=$CRUX_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url": "https://tinytickets.example/seats.html", "formFactor": "PHONE"}'
It needs your own Google Cloud API key, so this module prints no response. The response holds, for each metric, a histogram and percentiles.p75, plus the collectionPeriod it covers. A page without enough data returns HTTP 404 with “chrome ux report data not found”.
- Field only. A rolling 28-day window, updated daily at about 04:00 UTC and about two days behind. The separate History API returns the weekly points CrUX Vis draws.
- Limits: free, 150 queries per minute per Google Cloud project, and the quota can’t be raised by paying.
- When DevTools or your own data is better: for new pages, pages with little traffic, and any visitor CrUX leaves out.
CrUX leaves out many visitors (CrUX methodology). It counts only Chrome on desktop (Windows, macOS, ChromeOS, Linux) and on Android, for users with usage statistics reporting and history sync on. It excludes every browser on iOS, including Chrome there, plus Firefox, Safari, Android WebView and other Chromium browsers such as Edge. A page must be public and get enough traffic, but Google doesn’t publish the threshold.
Check yourself
Debugging scenario
The waiting page opens at 9:30, 30 minutes before a sale. A week after a sale, CrUX shows CLS 0.31 at the 75th percentile for the waiting page on phones. In the lab, PageSpeed Insights reports CLS 0.01. On the 6x phone profile, the console snippet prints no layout-shift line in the first 10 seconds.
Maya’s endpoint has one line from a buyer’s phone for that page. It reports CLS 0.31, with largestShiftTarget set to #queue, the buyer’s place in the queue, and largestShiftTime at 1,800,214 ms.
Why do the lab tools miss what the field sees, and what should Maya look for in the page?
Hint 1
Convert 1,800,214 ms to minutes, and compare it with the time the waiting page opens.
Hint 2
Which shifts does lab CLS count, and which does field CLS count?
Answer
1,800,214 ms is 30 minutes after the page loaded. A buyer who opened the page at 9:30 saw the shift at 10:00, when the sale opened. #queue is the element that moved, so something above it changed size or appeared at that moment.
Lab CLS counts only shifts during the load, and the snippet ran for 10 seconds, so neither saw a shift that happens half an hour later. But field CLS counts shifts for the whole life of the page. The buyer didn’t tap in the 500 ms before it, so the browser counted it.
Maya should look for code that runs at 10:00 and inserts or resizes an element above #queue. To reproduce it, she can load the page with the sale time set a few seconds away. Module 6 covers how to stop such shifts.
Review questions
- Field data and lab data disagree about a page. Which one decides what you fix, and what is the other one for?
- A page’s phone numbers at p75 are LCP 3.1 s, INP 180 ms and CLS 0.08. Does it pass the Core Web Vitals, and why?
- Why does
vitals.jssend its data when the page becomes hidden, and why does the queue use the metric’sid? - Name three groups of visitors CrUX doesn’t count.
- At 1x, the seat handlers ran for 76 ms, and at 6x for 373 ms. Why can a real slow phone still give a different number from the 6x profile?
Answers
- The field decides, because it’s what buyers lived through. The lab is for reproducing the symptom and finding its cause.
- No. LCP of 3.1 s is above 2.5 s, so it needs improvement, and a page passes only when all three are good.
- CLS and INP change for as long as the page is open, and a phone can close a tab without firing
unload, but the page becomes hidden first.web-vitalscan report the same metric more than once, so theidlets you keep only the last value for each page load. - Any three of: everyone on iOS (including Chrome there), Firefox users, Safari users, Android WebView, other Chromium browsers such as Edge, and Chrome users without usage statistics or history sync.
- CPU throttling slows only the main thread of your laptop. A real phone’s GPU, memory, disk and network are slower in their own ways, and a phone also slows down when it gets hot.
Lab: collect your own field data and compute p75
Time: about 15 minutes. You’ll need the lab app from this module, Chrome and Node.js.
- If you didn’t add them while reading, add
public/vitals.js, the<script type="module">line inseats.htmland thesaveVitalsendpoint from the fix section. Restartnode server.js. - In a normal Chrome window, open
http://localhost:8080/seats.html, tap one blue seat, then switch to another tab. Openvitals.ndjson. You should see three lines with"device":"desktop". - Set the phone profile: Slow 4G, 6x CPU, 412 × 823, device type “Desktop (touch)”, cache off. Load the page, tap a seat, and switch tabs. Do this four times. You should see lines with
"device":"phone"and"rating":"poor"for LCP and INP. - Write
p75.js, a script that readsvitals.ndjsonand prints the 75th percentile of each metric for each page and device class. Keep only the last line for eachid. For the percentile, sort the values and take the value at positionceil(0.75 × count), counting from 1. - Run
node p75.jsand compare the phone numbers with the field numbers in Figure 2.
A solution
import { readFile } from 'node:fs/promises';
const reports = (await readFile('vitals.ndjson', 'utf8'))
.trim()
.split('\n')
.map((line) => JSON.parse(line));
// A page load can report CLS or INP more than once. Keep the last report for each id.
const latest = new Map(reports.map((report) => [report.id, report]));
const groups = Map.groupBy(latest.values(), (r) => `${r.page} ${r.device} ${r.name}`);
for (const [group, metrics] of groups) {
const values = metrics.map((m) => m.value).sort((a, b) => a - b);
const p75 = values[Math.ceil(values.length * 0.75) - 1];
const shown = group.endsWith('CLS') ? p75.toFixed(3) : `${Math.round(p75)} ms`;
console.log(`${group}: p75 ${shown} from ${values.length} page loads`);
}
Map.groupBy needs Node.js 21 or later. Here’s the output from one laptop load and five phone-profile loads (one at 4x CPU, four at 6x), on the laptop described above. Your numbers will differ.
/seats.html desktop LCP: p75 684 ms from 1 page loads
/seats.html desktop INP: p75 152 ms from 1 page loads
/seats.html desktop CLS: p75 0.000 from 1 page loads
/seats.html phone LCP: p75 5364 ms from 5 page loads
/seats.html phone INP: p75 752 ms from 5 page loads
/seats.html phone CLS: p75 0.190 from 5 page loads
A p75 from five lab loads isn’t field data. The loads come from one laptop, one network and one tap each. The script is the same one you’d run over a day of buyers’ lines, and that’s when its number means something.
Stretch: add onFCP and onTTFB from the same library to vitals.js. Then add a release field with the version you deployed, so you can compare p75 before and after a change.
Cheat sheet
Measure before you guess
1. Field first: CrUX (Chrome only, 28 days) and your own web-vitals endpoint
2. Read p75 per page load, per device class; pass = all three good
3. LCP <= 2.5 s, INP <= 200 ms, CLS <= 0.1 (web.dev, read 2026-11-18)
4. Reproduce: throttle CPU and network until the lab shows the symptom
5. Throttling slows the main thread and the network, nothing else
6. Lab CLS stops at load; lab tools cannot measure INP without a tap
7. Follow each metric's element or event to the file before you change it
8. Send on visibilitychange to hidden; keep the last value per metric id
Figure 11 is the whole module in one picture. It shows the debugging loop of this course, with the two steps Module 1 taught.
[field data] --> [lab profile] --> [trace] --> [cause] --> [fix] --+
CrUX, your throttle until Module 2 Modules one |
endpoint, p75 the symptom shows 3 to 8 change |
^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ |
Module 1 Module 1 |
^ |
+------------ confirm with the next field data <--------------+
Figure 11: measure in the field, reproduce in the lab, and only then look for the cause.
Next, in Module 2, Maya records the tap in the Performance panel and finds one long block that nobody can read yet.
Sources
- Metrics and thresholds: Web Vitals, LCP, INP, CLS, defining the thresholds, lab and field data, evolving CLS, INP becomes a Core Web Vital, LCP and INP are Baseline.
- Specifications, for going deeper: Largest Contentful Paint, Event Timing, Layout Instability (a WICG draft, not a W3C standard).
- Chromium’s metric changelogs, for every change to how Chrome computes each metric: LCP, INP, CLS.
web-vitals: repository and README, version 6.2.3.- Sending data:
navigator.sendBeacon,keepalive, Page Lifecycle API. - CrUX: overview, methodology, API, History API, CrUX Vis.
- Throttling: DevTools throttling settings, calibrated CPU throttling, Lighthouse throttling, and the presets in the DevTools source,
front_end/core/sdk/NetworkManager.ts.