completefrontend
Open lab My progress
THE WEB PERFORMANCE FIELD GUIDE

Project: fix a slow store

Take the course's slow store from failing to passing Core Web Vitals: a lab and field baseline, then LCP, CLS, INP and a third party, fixed one at a time.

By the end, you can
  • 01
    Take a baseline in the lab and the fieldMeasure the store several times under one lab setting, read its p75s from many visits, and compare both with Google's lines.
  • 02
    Fix one problem at a timeFor each Core Web Vital and the third party: measure, find the cause with the right tool, change one thing, then measure again.
  • 03
    Report the before and afterWrite the project up the way lesson 40.2 taught, from the recorded numbers, with what changed, what didn't, and what comes next.

From failing to passing, one fix at a time

Asha opens the Leaf and Kettle store on her phone, on the bus. For three seconds, the screen stays white. Then the words appear, with an empty space where the picture of mint tea should be. A yellow promotion slides in at the top and pushes everything down. The picture comes last, after six and a half seconds. She taps Add to cart. Nothing happens for a third of a second.

This is the course's slow store, from lesson 1.4. Ravi built it with one problem for loading, one for responding and one for stability. Since then, it has also gained a chat widget, like the one in lesson 24.1. Ravi has met every fix it needs, somewhere in this course. So which one comes first? And how will he know that each one worked?

Here is where the project ends. These are the store's numbers in the lab, before and after:

The store, before and after the projectPop out in the code editor (opens in a new tab)JavaScript
// The store in the lab: the middle of 5 loads, before and after the projectconst before = { LCP: 6508, INP: 352, CLS: 0.14 };const after = { LCP: 1260, INP: 48, CLS: 0 };const good = { LCP: 2500, INP: 200, CLS: 0.1 }; for (const metric of ["LCP", "INP", "CLS"]) {  console.log(`${metric}: ${before[metric]} before, ${after[metric]} after. Good is up to ${good[metric]}.`);}
  • Line 1 is a comment. The lab is the course's own computer, set up to act like Asha's phone. Each number is the middle of 5 loads.
  • Lines 2 and 3 hold the three Core Web Vitals. LCP is when the biggest picture or text appeared, in ms. INP is how long a tap took to show its result, in ms. CLS is a score for how much the page jumped.
  • Line 4 holds Google's line for "good" for each one.
  • Lines 6 to 8 print one line per metric. The first is LCP: 6508 before, 1260 after. Good is up to 2500.

All three numbers crossed their lines. Here is what that looks like on the phone's screen. These are real frames, at the same moments, before the project and after it:

The store loading in the lab on a phone, before the project and after it, at four moments. At 1.3 s: before, a blank screen; after, the picture and the chat bubble, under the kept room. At 2.5 s: before, a blank screen; after, the picture, the first teas and the chat bubble, under the kept room. At 4.0 s: before, the words and the first teas, but no picture; after, the whole page, with Cart: 1 after the tap. At 6.5 s: before, the picture, at last; after, the whole page, with Cart: 1 after the tap.beforeafter1.3 sThe store showing a blank screenThe store showing the picture and the chat bubble, under the kept room2.5 sThe store showing a blank screenThe store showing the picture, the first teas and the chat bubble, under the kept room4.0 sThe store showing the words and the first teas, but no pictureThe store showing the whole page, with Cart: 1 after the tap6.5 sThe store showing the picture, at lastThe store showing the whole page, with Cart: 1 after the tap
The same phone and network, before the project (top) and after it (bottom). Each column is one moment. After, the picture is there by 1.3 s. Before, it only comes at 6.5 s.

So how do you get from the top row to the bottom one? Not by changing everything at once.

Real-life analogyA mechanic's test drive

You tell a mechanic that your car feels slow. She doesn't start by changing parts. She drives it first, and writes down what it does. Then she finds the cause with the right tool, changes one part, and drives it again. If she changed three parts at once, she couldn't tell which one helped.

In real life: The first test drive, written down
In web performance: The baseline: the store's numbers before any change
In real life: The right tool for each noise
In web performance: DevTools' insights, the trace, and the web-vitals attribution
In real life: Changing one part
In web performance: One change to the store's files
In real life: Another test drive, on the same road
In web performance: Measuring again, the same way as before
The main idea

Fix a slow page in a loop: measure, find the cause with the right tool, change one thing, and measure again the same way. Start with a baseline from the lab and the field. End with a report that shows the before and the after.

The project has four steps, one per problem, and then a report:

  • Step 1, LCP: the picture comes last.
  • Step 2, CLS: the promotion pushes the page down.
  • Step 3, INP: Add to cart is slow to answer.
  • Step 4, third parties: the chat widget costs every visit.

Each step uses a fix from an earlier lesson, and links to it. Do each step on your own copy of the store as you read, and measure it the way lesson 1.4 showed.

How the course recorded it

  • The store: one version before the steps, and one after each step. Each was served over HTTPS from the course's computer, at made-up addresses: shop.example for the store and chat.example for the widget. The files went out as they are, with no compression, as in lesson 1.4.
  • The lab: Chrome 157 as Asha's phone. That's Lighthouse's phone screen, DevTools' Slow 4G network and the CPU 4× slower. Each version loaded 5 times, taking turns, after one round that wasn't kept. Each load waited for the page to settle, then tapped Add to cart with the mouse. DevTools' own trace engine read every trace.
  • The field: 120 visitors the course simulated, 84 on phones and 36 on computers. Each one got its own CPU speed and network, drawn the way lesson 13.1 drew them. Each visitor met the store twice: once before the project and once after it. That's 240 visits.
  • The numbers: every visit and every lab load sent its own numbers home with the web-vitals library. The course added that small script to every version while recording. The published copies leave it out.

Measure the store before you change it

A baseline is a page's numbers before you change anything. Ravi takes two. The lab baseline helps him see why the store is slow. The field baseline tells him how slow it is for real visitors. Lesson 3.3 showed why you need both.

The project's store

The project starts from lesson 1.4's store, file for file. It adds one line, near the end of the page:

index.html: the one new lineHTML
    <section id="teas"></section>  </main>  <script src="https://chat.example/widget.js" async></script></body>
  • Lines 1 and 2 are the end of the store's page, as lesson 1.4 left it.
  • Line 3 is new. It loads lesson 24.1's chat widget from another site, chat.example. Code from another site is a third party. With async, the browser downloads it without stopping, and runs it as soon as it arrives.

Get your copy now. Each version of the store is published in its own folder, so you can compare it with yours after each step. Lesson 1.4 showed how to serve the files on your computer. Save page.html as index.html:

The widget's address is the stand-in from lesson 24.1. Only the course's recorder answered it. On your copy, its request fails, so the widget never runs. Step 4 reads its cost from the recorded trace instead.

The lab baseline

Ravi loads the store 5 times in the lab, and keeps the middle value of each number. The playground below holds the store's numbers before the project and after each step, with the frames of each one's middle load. Start on Before:

Playground: the store at each checkpoint
In the labBefore
  1. First contentful paint (FCP)2,948 ms
  2. Largest contentful paint (LCP)6,508 mspoor
  3. Add to cart's INP352 msneeds improvement
  4. Layout shift score (CLS)0.14needs improvement
  5. Long tasks during the load5, 974 ms in all
  6. Add to cart starts working3,084 ms
  7. Bytes over the network865 KB
What the screen showed7 frames
  1. a blank screen7 msa blank screen
  2. the words, with an empty space for the picture2,952 msthe words, with an empty space for the picture
  3. the words and the first teas, but no picture3,105 msthe words and the first teas, but no picture
  4. the promotion, which pushed the words down4,104 msthe promotion, which pushed the words down
  5. the promotion and the chat bubble, but no picture6,038 msthe promotion and the chat bubble, but no picture
  6. the picture, at last6,506 msthe picture, at last
  7. the whole page, with Cart: 1 after the tap7,625 msthe whole page, with Cart: 1 after the tap
Try it yourself
Before: 0 of 3 Core Web Vitals good in the lab

Lesson 1.4's store, plus the chat widget from lesson 24.1. Nothing is fixed yet.

Each number is the middle of five lab loads in Chrome 157, on Lighthouse's phone screen with Slow 4G and the CPU 4× slower. The frames are the middle load's, by LCP.

Before any fix, LCP was 6,508 ms: poor. Add to cart took 352 ms, and CLS was 0.14. Both of those need improvement. Click through the other versions to see where the project goes. Why it matters: every step is compared with these numbers, measured the same way.

The field baseline

The lab is one phone on one network. Real visitors use many. So Ravi also needs field data: numbers from real visits. Google rates a page by the 75th percentile of its visits, the p75. Three visits in four were at that number or better. Lesson 3.4 explained why. Here are the p75s of the store's field sample, before the project:

Does the store pass?Pop out in the code editor (opens in a new tab)JavaScript
// The store's field baseline: the p75 of its visits, before any fixconst p75 = { LCP: 3508, INP: 344, CLS: 0.14 };const good = { LCP: 2500, INP: 200, CLS: 0.1 }; const over = Object.keys(p75).filter((metric) => p75[metric] > good[metric]);console.log(`Over the line: ${over.join(", ") || "none"}`);console.log(over.length ? "The store fails Core Web Vitals." : "The store passes Core Web Vitals.");
  • Line 2 holds the p75 of the 120 visits before the project, for each metric.
  • Line 3 holds Google's good lines.
  • Line 5 keeps each metric whose p75 is over its line.
  • Line 6 prints Over the line: LCP, INP, CLS. Line 7 prints The store fails Core Web Vitals.

To pass, all three p75s must be at or under their lines. The store failed all three. Read the table across: each row is one metric.

The store's baseline, in the lab and in the field
MetricLab: middle of 5 loadsField: p75 of the visitsGoogle's good line
LCP6,508 ms3,508 ms2,500 ms
INP352 ms344 ms200 ms
CLS0.140.140.1

Look at LCP. The field's p75 was 3,508 ms, much less than the lab's 6,508 ms. 72 of the 84 phones in the sample had a faster network than Slow 4G. The lab setting is a slow phone on a slow network, on purpose. It makes each problem big and easy to see. Why it matters: use the lab to find causes, and the field to say how many visitors are hurt.

Every visit over a line came from a phone: all 84 of them. None of the 36 visits from computers was over any line. Lesson 12.5 showed why you split visits by device.

The field also says where to look. The RUM script sends attribution with each number: which element it was about. On every visit, the LCP element was #hero, the picture. Every tap was on #add. And the largest shift always moved html>body>main, the main area. Each one points at a step of the project.

Step 1: the picture comes last

Measure. In the lab, the picture appeared at 6,508 ms. That's LCP, and Google's line is 2,500 ms.

Find the cause. LCP has four parts, one after another (lesson 17.2). Each part points at a different fix. DevTools' LCP breakdown insight shows them for any trace. The web-vitals attribution build sends the same four parts from every visit. Here they are for the middle load:

The picture's LCP, in four partsPop out in the code editor (opens in a new tab)JavaScript
// The picture's LCP in four parts (ms), from the RUM script's attributionconst parts = {  "time to first byte": 563.8,  "resource load delay": 43,  "resource load duration": 5496.2,  "element render delay": 405,};const biggest = Object.keys(parts).reduce((a, b) => (parts[a] >= parts[b] ? a : b));console.log(`Biggest part: ${biggest}, ${parts[biggest]} ms`);
  • Lines 2 to 7 hold the four parts, in ms. Added up, they make the LCP.
  • Line 8 finds the biggest part.
  • Line 9 prints Biggest part: resource load duration, 5496.2 ms.

Almost all of the wait was the picture downloading. It weighs 580 KB, because of a texture of 14,000 tiny dots, from lesson 1.2. The dots are so faint you can hardly see them.

Real-life analogyA parcel in a wardrobe box

A shop sends you a small parcel in a wardrobe-sized box. The van takes all day. The shop learns, and sends the next one in an envelope. It arrives in the morning, but sits on the doormat. Your door stays locked until someone finishes reading a long letter aloud. Unlock the door first, and the envelope comes straight in.

In real life: The wardrobe-sized box
In web performance: The 580 KB picture, heavy with its texture
In real life: The same parcel in an envelope
In web performance: The picture without the texture
In real life: The door, locked until the letter is read
In web performance: app.js, a classic script in the head
In real life: Unlocking the door first
In web performance: The defer attribute on app.js

Change one thing. Ravi exports the same picture without the texture. The file goes from 580,632 bytes to 2,819. Lesson 18.5 shows how to slim an SVG.

Measure again. LCP fell to 2,388 ms. That's under the line, but only just. And the parts changed shape. Now the biggest was the element render delay, 1,176 ms. The picture arrived, then waited.

What for? For app.js, a classic script in the head, on line 8 of index.html. The browser can't draw anything until it has downloaded and run that script (lesson 5.3). So the first paint and LCP came together, at 2,388 ms.

Change one more thing. It takes one word:

index.html: defer on app.jsHTML
<!-- index.html, line 8, before the change --><script src="app.js"></script> <!-- line 8 after it: one word added --><script src="app.js" defer></script>
  • Line 2 is the old line 8: a classic script, which stops the page until it has run.
  • Line 5 is the new line 8. defer tells the browser to download the script without stopping, and to run it once the page has been read.

The store's code waits for DOMContentLoaded anyway, so it still works. Lesson 17.4 took apart a script in the head like this one.

Measure again. LCP fell to 1,256 ms. The element render delay fell to 20 ms. Here are the three middle loads, split into their four parts and drawn to scale:

The LCP of the middle lab load in four parts, drawn to scale. before: 6,508 ms, time to first byte 564 ms, resource load delay 43 ms, resource load duration 5,496 ms, element render delay 405 ms. lighter picture: 2,388 ms, time to first byte 564 ms, resource load delay 43 ms, resource load duration 605 ms, element render delay 1,176 ms. with defer too: 1,256 ms, time to first byte 564 ms, resource load delay 43 ms, resource load duration 630 ms, element render delay 20 ms. A dashed line marks Google's line for a good LCP, 2,500 ms.good: 2,500 msbefore6,508 msbiggest: resource load durationlighter picture2,388 msbiggest: element render delaywith defer too1,256 msbiggest: resource load duration0 s2 s4 s6 s
Each bar is one load's LCP, split into its four parts in order. Shaded: the two parts spent on the network. The lighter picture shrank the download, and the render delay became the biggest part. Then defer shrank that too.

Each change fixed the part it aimed at, and showed the next one. Two changes measured together would have hidden that.

Did anything else move? CLS stayed at 0.14 and INP at 344 ms: the next two steps. But one number got worse. Add to cart started working later: at 3,160 ms, not 2,516 ms. Why? A classic script in the head starts at high priority. With defer, app.js starts low, like the async chat widget (lesson 5.4). So the two now share the slow network, and app.js finished at 2,876 ms instead of 2,330 ms. Step 4 wins that back.

Check your copy. This viewer shows every line each step changed:

Playground: what each step changed
index.html−1 +1
  1. 66 <title>Leaf and Kettle</title>
  2. 77 <link rel="stylesheet" href="styles.css">
  3. 8 <script src="app.js"></script> (removed)
  4. 8 <script src="app.js" defer></script> (added)
  5. 99</head>
  6. 1010<body>
hero.svg−14,002 +0
  1. 2727 <text x="300" y="132" font-family="Georgia, serif" font-size="20" fill="#3f6f31" text-anchor="middle">Mint</text>
  2. 2828 <text x="300" y="154" font-family="Georgia, serif" font-size="14" fill="#6b5a3e" text-anchor="middle">fresh this week</text>
  3. 29<g fill="#3f6f31" opacity=".08"> (removed)
  4. 30 <circle cx="0.1" cy="160.7" r="0.9"/> (removed)
  5. 31 <circle cx="75.4" cy="65.1" r="0.9"/> (removed)
  6. … 13,998 more lines like these …
  7. 14030</g> (removed)
  8. 1403129</svg>
Try it yourself
Fixing LCP: 2 files, 14,003 lines removed, 1 added

Red lines left the store, green lines joined it. The grey lines around them didn't change. The numbers are line numbers before and after the step.

The same change as the published checkpoints. Download two neighbouring checkpoints and compare them to check your own copy.

Step 2: keep room for the promotion

Measure. After step 1, CLS was 0.14 in all 5 loads, over the 0.1 line. One layout shift each time: a jump of content that nobody asked for.

Find the cause. Each layout shift lists the elements it moved, and where they were before and after (lesson 30.4). The web-vitals attribution build reports the largest shift: when it happened, and the first element it moved, in page order:

The largest shift, as the RUM script reported itPop out in the code editor (opens in a new tab)JavaScript
// The largest layout shift, from web-vitals' attribution buildconst shift = { element: "html>body>main", at: 4165, top: [50, 170] }; console.log(`${shift.element} moved down ${shift.top[1] - shift.top[0]} px at ${shift.at} ms`);
  • Line 2 holds its report from the middle load: the element, when it moved, and its top edge before and after, in px.
  • Line 4 prints html>body>main moved down 120 px at 4165 ms.

The whole main area moved down 120 px, a second after the store's code ran. That's the promotion. A second after DOMContentLoaded, app.js puts it into the empty #news box, above everything (lesson 30.2). On the phone's screen, the promotion is 120 px tall.

One tool guessed wrong. DevTools' Layout shift culprits insight named the picture, as an "Unsized image element". Its docs call that a best guess. Chrome counts a picture as unsized unless its CSS fixes both its width and its height, and the store's CSS says height: auto. But the width and height in the HTML already keep the picture's room. And it had been on screen for nearly three seconds. It was painted again only because it moved. Why it matters: check what a tool blames against when the jump happened and what moved.

Real-life analogySaving a seat at the cinema

Your friend is running late for a film. You put your coat on the seat next to you. When she arrives, she sits down, and nobody else in the row has to move.

In real life: Your coat on the empty seat
In web performance: #news { min-height: 120px; }
In real life: The friend who comes late
In web performance: The promotion, a second after the page is ready
In real life: The whole row shuffling along
In web performance: The layout shift

Change one thing. Keep the room from the start, as lesson 30.3 did for an ad:

styles.css: room for the promotionCSS
/* styles.css, a new last line: keep the promotion's room */#news { min-height: 120px; }

Line 1 is a comment. Line 2 gives the empty box a min-height: it's at least 120 px tall from the start. When the promotion arrives, it fills that room. Ravi also updates the comment above the promotion in app.js, so it stays true.

Measure again. CLS was 0 in all 5 loads. Pick After CLS in the playground above. Its frames show the empty room first, then the promotion inside it.

On a computer, the promotion fits on one line, so it's shorter than 120 px. It leaves a small gap, and nothing moves. In the field sample after the project, every visit from a computer had a CLS of 0. Why it matters: keep room for the tallest thing that can arrive. A smaller one leaves a gap, not a jump.

Step 3: a tap that only updates the cart

Measure. A tap on Add to cart took 352 ms to show its result. With one tap, that's the visit's INP. It needs improvement.

Find the cause. INP has three parts (lesson 26.2). The input delay waits for the main thread. The processing runs the tap's code. The presentation delay draws the new screen. For the middle load, they were 2 ms, 176 ms and 174 ms. Almost nothing waited. The time went on the store's own code, and on drawing what it changed.

Whose code? The trace's flame chart under the click names the functions (lesson 26.3). buildIndex ran for 130 ms, and showTeas for 35 ms. Here is the tap's handler:

app.js: what a tap on Add to cart ranJavaScript
document.querySelector("#add").addEventListener("click", () => {  count = count + 1;  document.querySelector("#cart").textContent = `Cart: ${count}`;  // Every click rebuilds the index and draws all 1,800 teas again.  buildIndex();  showTeas(catalog.length);});
  • Line 1 runs the function on every click of Add to cart.
  • Lines 2 and 3 count the click and show it: the only change Asha needs.
  • Line 4 is a comment. Line 5 sorts 200,000 prices again. Line 6 draws all 1,800 teas.

Neither the prices nor the teas had changed. The list even grew from 24 teas to 1,800, below the screen, though nobody asked for that. Drawing them was the long presentation delay.

Real-life analogyA shop assistant who counts the stockroom

You buy one packet of tea. Before handing you the receipt, the assistant counts every box in the stockroom. Then they rewrite the whole price list. Nothing in the stockroom changed. You only wanted your receipt.

In real life: Handing over the receipt
In web performance: Showing Cart: 1
In real life: Counting every box in the stockroom
In web performance: buildIndex sorting 200,000 prices
In real life: Rewriting the whole price list
In web performance: showTeas drawing 1,800 teas
In real life: The customer, waiting at the till
In web performance: INP

Change one thing. Delete lines 4 to 6. The fastest work is work you skip (lesson 27.3). If some of it were needed, you'd show the change first, then yield (lesson 28.1).

Measure again. INP fell to 40 ms. Processing fell to 4 ms, and the list stays at 24 teas.

The field sample tells the same story from real taps. Its INP attribution includes the longest script that ran during the tap, from the Long Animation Frames API (lesson 11.5). On every visit before the project, it was app.js, started by BUTTON#add.onclick, during processing.

Step 4: the chat widget waits for a tap

Measure. After step 3, all three Core Web Vitals were good in the lab. But the trace still showed 3 long tasks during the load: stretches of 50 ms or more when the main thread can't answer a tap. Together they took 607 ms. Whose were they?

Find the cause. DevTools' 3rd parties insight groups a trace's work by who owns the code. For this store, chat.example sent 129 KB and kept the main thread busy for 447 ms. That's the chat widget (lesson 24.1). It sets itself up, asks its server for its settings, then draws its bubble. And its bytes share Asha's network with the store's own app.js.

Real-life analogyA bell on the counter

A small shop has a helper who stands by the door all day, in everyone's way, though few customers need help. So the owner puts a bell on the counter. The helper comes out only when someone rings it.

In real life: A helper standing by the door all day
In web performance: The widget, loaded on every visit
In real life: The bell on the counter
In web performance: The facade: a button that looks like the bubble
In real life: Ringing the bell
In web performance: Tapping the bubble, which loads the real widget
In real life: Customers who never ring
In web performance: Visitors who never chat, and pay nothing for it

Change one thing. A facade is a light copy of a widget that loads the real one only when tapped (lesson 24.2). It replaces line 21 of index.html:

index.html: the chat bubble's facadeHTML
<button class="chat-bubble" type="button" aria-label="Chat with Ravi"></button><script>  document.querySelector(".chat-bubble").addEventListener("click", (event) => {    const widget = document.createElement("script");    widget.src = "https://chat.example/widget.js";    document.body.append(widget);    event.currentTarget.remove();  }, { once: true });</script>
  • Line 1 is a button that looks like the widget's bubble. styles.css gets the bubble's style too.
  • Lines 3 to 8 run on the first tap only, because of once: true on line 8.
  • Lines 4 to 6 add the real widget's script. Line 7 removes the facade.

Measure again. chat.example was gone from the trace. One long task was left: the store's own start-up work, 165 ms. The page downloaded 129 KB less. And with the network to itself, app.js finished at 2,161 ms instead of 2,869 ms. So Add to cart started working at 2,322 ms instead of 3,153 ms. LCP stayed about the same: 1,260 ms. The picture had already appeared before the widget arrived.

Why it matters: a third party can cost a lot and still not move the three vitals in one test. Count its bytes and its time on the main thread too.

Before and after: the report

Four steps are done. First, each step against the number it set out to move, in the lab:

What each step changed in the lab, the middle of five loads. Step 1, LCP: 6,508 ms before, 1,256 ms after, against a good line of 2,500 ms. Step 2, CLS: 0.14 before, 0 after, against a good line of 0.1. Step 3, INP: 352 ms before, 40 ms after, against a good line of 200 ms. Step 4, long tasks: 607 ms before, 165 ms after.Step 1LCP6,508 ms1,256 msgood: 2,500 msStep 2CLS0.140good: 0.1Step 3INP352 ms40 msgood: 200 msStep 4long tasks607 ms165 ms
Each step, and the number it set out to move. Plain: before the step. Shaded: after it. A dashed line marks Google's line for good. The last step has no line: it's the main thread's long tasks during the load.

Each step moved its own number a long way. The other Core Web Vitals barely moved: LCP and INP by 8 ms or less, and CLS not at all. That's noise. Event Timing rounds each tap's duration to 8 ms, and LCP moves about that much from load to load. One other number got worse for a while: when Add to cart starts working, in step 1. Step 4 won it back. The step picker has every version's numbers, if you want to check.

Read this table across: each row is one step.

The four steps at a glance
StepWhich tool found the cause?What changed?Which lesson taught it?
Step 1: LCPThe LCP breakdown. It showed the download first, then the render delay.A lighter picture, then defer on app.js.Lessons 17.2, 17.4 and 18.5.
Step 2: CLSThe shift's attribution: what moved, how far, and when.min-height keeps the promotion's room.Lessons 30.2, 30.3 and 30.4.
Step 3: INPINP's three parts, then the flame chart under the click.A tap only updates the cart.Lessons 26.2, 26.3 and 27.3.
Step 4: third partiesThe 3rd parties insight. It named the chat widget's site.A facade loads the widget on a tap.Lessons 24.1 and 24.2.

The field, after the project

Then the same 120 visitors met the finished store. Here are their p75s, before and after:

The p75 of the field sample, before the project and after it. LCP: 3,508 ms before, 448 ms after, against a good line of 2,500 ms. INP: 344 ms before, 48 ms after, against a good line of 200 ms. CLS: 0.14 before, 0 after, against a good line of 0.1.LCP3,508 ms448 msgood: 2,500 msINP344 ms48 msgood: 200 msCLS0.140good: 0.1
The p75 of the 120 visitors' visits, before the project (plain) and after it (shaded). Before, all three were past Google's line for good. After, all three are under it.

All three are good now. LCP went from 3,508 ms to 448 ms, INP from 344 ms to 48 ms, and CLS from 0.14 to 0. Pick phones or computers to see each group on its own:

Playground: the field, before and after
The p75 of each metricAll visits
  1. LCP before3,508 msneeds improvement
  2. LCP after448 msgood
  3. INP before344 msneeds improvement
  4. INP after48 msgood
  5. CLS before0.14needs improvement
  6. CLS after0good
Try it yourself
All visits: failed before, passes after

The p75 of 120 visits before the project, and of the same visitors' 120 visits after it. Passing means all three p75s are good.

The course's field sample: 120 visitors, each with their own phone or computer and network, who met the store before the project and after it.

Before, 84 of the 120 visits were over at least one line. After, none were. Why it matters: that's the number the owner cares about. It counts visitors, not milliseconds.

The report

Ravi writes it up the way lesson 40.2 taught. The answer comes first. Then the findings, the actions, how he'll know it stays fixed, and how he measured:

Ravi's reportText
# Speed project: the Leaf and Kettle store## SummaryThe store now passes all three Core Web Vitals. Before, it failed all three.Four steps did it: 19 changed lines of code, and one lighter picture.## FindingsLCP: one visit in four waited 3.5 s or more for the picture. Now 0.4 s.CLS: 0.14 at p75, from a late promotion that pushed the page down 120 px. Now 0.INP: one tap in four took 344 ms or more. Now 48 ms.The chat widget cost every visit 129 KB and 447 ms of main-thread work.## ActionsDone: a lighter picture, defer, room for the promotion, a lighter tap, a chat facade.Next, Meera, day 5: split app.js, so Add to cart works sooner.## How we'll know it stays fixedEach week, read the p75s from our RUM, and alert if one goes over its line.## How we measured120 simulated visitors, before and after. Lab: Chrome 157, Slow 4G, CPU 4×, middle of 5 loads.
  • Line 1 is the title.
  • Lines 2 to 4 are the summary: what changed, and what it cost.
  • Lines 5 to 9 are the findings: one problem per line, with its numbers.
  • Lines 10 to 12 are the actions: what's done, and what comes next, with a name and a day.
  • Lines 13 and 14 say how he'll know it stays fixed.
  • Lines 15 and 16 say how he measured. They come last, because only engineers need them.

Line 12 is honest about what's left. app.js is still 153 KB, mostly the 1,800-tea catalog. Add to cart only works once it has arrived. Splitting it is the next job (lesson 22.4).

One thing the report can't say yet: whether a faster store sells more tea. That takes an experiment with real visitors, as lesson 40.3 showed.

Which step fixes it?

Each problem below is one the project met. Sort it into the step that fixes it:

Which step fixes it?
  • The picture weighs 580 KB because of a texture of tiny dots
  • The picture has arrived, but a script in the head hasn't run yet
  • A promotion appears above the page a second after it's ready
  • An empty box gets taller when its content arrives
  • A tap sorts 200,000 prices that didn't change
  • A tap redraws 1,800 teas when only the cart changed
  • A chat widget from another site downloads on every visit
  • Code from another site keeps the main thread busy during the load
Try it yourself
0 of 8 correct

Sort each problem into the step of the project that fixes it.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Common mix-ups

  • "Fixing everything at once saves time." No. With one change per measurement, you know what each change did. The LCP step needed two changes, and each one showed the next problem.
  • "If the lab passes, the field passes." No. The lab is one phone on one network. Google rates the p75 of real visits, on every phone and network.
  • "The lab is always faster than real visitors." No. Here the lab's LCP was slower than the field's p75, because its network is slower than most visitors'.
  • "An async third-party script costs nothing." No. It still downloads, and it still runs on the main thread. The chat widget cost 129 KB and 447 ms on every visit.
  • "A tool's insight always names the cause." No. The layout shift insight blamed the picture. The time of the jump and the element that moved pointed at the promotion.
  • "A Core Web Vital that passes means the page has no problems left." No. After all three passed, the widget still kept the main thread busy, and Add to cart still waited for 153 KB of script.

Practice exercises

Answer first, then use the hints. The DevTools exercises use the two traces the course published.

Exercise 1 · Warm-upAnother store's p75s

Another store measured these p75s. What does line 6 print?

Starter codePop out in the code editor (opens in a new tab)JavaScript
// Another store's p75s, made up for this exercise
const p75 = { LCP: 2400, INP: 210, CLS: 0.05 };
const good = { LCP: 2500, INP: 200, CLS: 0.1 };

const over = Object.keys(p75).filter((metric) => p75[metric] > good[metric]);
console.log(`Over the line: ${over.join(", ") || "none"}`);
console.log(over.length ? "The store fails Core Web Vitals." : "The store passes Core Web Vitals.");

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upLong tasks before any fix

    In the step picker, pick Before. How many long tasks ran during the load?

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeThe parts after the lighter picture

      These are the four parts with the lighter picture, before defer. What does the program print?

      Starter codePop out in the code editor (opens in a new tab)JavaScript
      // The four parts with the lighter picture, before defer (ms)
      const parts = {
        "time to first byte": 563.6,
        "resource load delay": 43.3,
        "resource load duration": 604.7,
        "element render delay": 1176.4,
      };
      const biggest = Object.keys(parts).reduce((a, b) => (parts[a] >= parts[b] ? a : b));
      console.log(`Biggest part: ${biggest}, ${parts[biggest]} ms`);

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeLines the INP step removed

        How many lines did the INP step remove from app.js?

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeThe widget's requests

          Open the before trace in DevTools' Performance panel. How many requests did the store send to chat.example?

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeThe first file after the HTML

            In the before trace, which file did the browser ask for first, after the HTML itself?

            Answer, then press Check. Spacing and letter case don’t matter.

              Check your understanding

              For each question, ask yourself which step it's about, and which tool found the cause.

              The slow store project quiz · 7 questionsScore: first tries count
              1. Question 1 of 7Why does the project change only one thing between two measurements?

                Choose an answer to see the explanation.

              2. Question 2 of 7With the lighter picture, the biggest part of LCP became the element render delay. What was the picture waiting for?

                Choose an answer to see the explanation.

              3. Question 3 of 7Which tool pointed at buildIndex and showTeas as the cause of the slow tap?

                Choose an answer to see the explanation.

              4. Question 4 of 7The third-party step barely moved LCP in the lab. Why was it still worth doing?

                Choose an answer to see the explanation.

              5. Question 5 of 7Why does the report judge the store by the p75 of many visits, not by the lab's middle load?

                Choose an answer to see the explanation.

              6. Question 6 of 7On a computer screen, the promotion is shorter than the room the CLS step keeps. What happens when it arrives?

                Choose an answer to see the explanation.

              7. Question 7 of 7What does the first line of this check print?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                // Another store's p75s, made up for this question
                const p75 = { LCP: 2300, INP: 180, CLS: 0.12 };
                const good = { LCP: 2500, INP: 200, CLS: 0.1 };
                
                const over = Object.keys(p75).filter((metric) => p75[metric] > good[metric]);
                console.log(`Over the line: ${over.join(", ") || "none"}`);
                console.log(over.length ? "The store fails Core Web Vitals." : "The store passes Core Web Vitals.");

                Choose an answer to see the explanation.

              Key takeaways

              • Take a baseline first: the middle of several lab loads, and the p75 of many field visits.
              • Work in a loop: measure, find the cause with the right tool, change one thing, measure again.
              • The LCP breakdown, INP's parts, a shift's moved elements and the 3rd parties insight each point at one fix.
              • One fix can show the next problem: the lighter picture showed the script in the head.
              • Count what the vitals miss: a third party's bytes and its main-thread time.
              • Report the before and after with the answer first, and say what's left.

              Remember the one-liner.
              Measure, find the cause, change one thing, measure again; then show the before and after.

              Sources

              The facts on this page come from these standards and docs:

              Coming next: Project: build a RUM dashboard. You'll collect numbers like this project's field data from real visits, and chart them by segment.

              CompleteFrontend Clear concepts. Working examples.