Leo opened the old show page for Midsummer Lights, the stadium show, on his phone on the bus home. The header and the text appeared after about two seconds. The picture of the stadium came last, long after he had read the date.
“Should the picture take that long?” Leo wrote.
“No,” Maya wrote back. “On a phone, that picture is what the page waits for.”
Maya, Leo and TinyTickets are invented, and so are the numbers in their story.
This module is about the first load of a page, from the request for the HTML until the largest element is painted. You’ll split Largest Contentful Paint (LCP) into its four parts, follow the largest part into the network waterfall, and fix the show page one change at a time. The same method works on any page with a poor LCP.
After this module, you can:
- split an LCP into its four parts, and say which part to work on first
- read a network waterfall: when each request starts, at which priority, and which request or chain it waited for
- tell render-blocking from parser-blocking resources, and predict whether removing one moves the first paint
- choose between removing lazy loading,
fetchpriority,preloadandpreconnectfor a late resource, and name what each one costs - serve an image sized for the screen with
srcset,sizesand AVIF, and read the server’s share of TTFB fromServer-Timing
What buyers waited for on the show page
Buyers reach the seat map from a show page: a picture, the show’s details and a Buy button. Every show uses the same page template.
CrUX has data for the stadium show’s page. On phones, in the 28-day window that held the sale, its LCP at the 75th percentile was 4.4 s. Anything over 4.0 s is poor.
Maya’s own endpoint from Module 1 told her more. vitals.js runs on every TinyTickets page. In the last week, 1,312 LCP lines came from phones on show pages for next month’s shows. Their 75th percentile was 4.1 s, and in 1,270 of them the LCP element was the show’s picture, html>body>main>img.
Pause and predict. The show page loads one HTML file, two stylesheets, three scripts in <head> and one picture. On the phone profile, when does the request for the picture start: as soon as the HTML arrives, or later? Write down a time in seconds.
Build the show page and reproduce the slow load
The show page joins the lab app from Module 2. Add three files to public/. They’re the page as TinyTickets served it on sale day, with the template’s choices as they were.
public/show.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Midsummer Lights - TinyTickets</title>
<link rel="stylesheet" href="/show.css">
<script src="http://127.0.0.1:8081/analytics.js"></script>
<script src="/show.js"></script>
<script type="module" src="/vitals.js"></script>
</head>
<body>
<header>TinyTickets</header>
<main>
<img src="/stadium.jpg" loading="lazy" alt="The stadium, with the stage at the north end">
<h1>Midsummer Lights</h1>
<p class="when">June 20, gates open at 17:00. The stadium, 60,000 seats.</p>
<p>One night of music under the open sky, presented by Leo. Every seat faces the stage.</p>
<p class="price">Tickets $60 and $95</p>
<a class="buy" href="/seats.html">Buy tickets</a>
<button id="share" type="button" hidden>Share</button>
</main>
</body>
</html>
The template puts loading="lazy" on every image, and the picture is the same stadium.jpg the seat map uses: 1600 × 900 px, 704 KB. analytics.js is the synchronous third-party script from Module 1, which Module 7 deals with.
public/show.css starts by importing the site’s base stylesheet, then adds the page’s own rules:
@import url('/styles.css');
h1 { margin: 16px 0 4px; font-size: 28px; line-height: 1.2; }
.when { margin: 0; font-weight: 700; }
.price { font-size: 20px; }
.buy {
display: inline-block;
padding: 12px 24px;
border-radius: 8px;
background: #e8590c;
color: #fff;
font-weight: 700;
text-decoration: none;
}
#share { margin-left: 8px; padding: 12px 16px; font: inherit; }
public/show.js shows a Share button once the page is parsed:
// Shows the Share button, which copies the page's address.
document.addEventListener('DOMContentLoaded', () => {
const button = document.getElementById('share');
button.hidden = false;
button.addEventListener('click', async () => {
await navigator.clipboard.writeText(location.href);
button.textContent = 'Link copied';
});
});
Add one header to the lab server too. In serveFile in server.js, keep the delay in a variable, time the file read, and send a Server-Timing header with both. The section on Server-Timing near the end of this module explains what it’s for.
async function serveFile(req, res, folder) {
const url = new URL(req.url, 'http://localhost');
const delay = Number(url.searchParams.get('delay')) || 0;
await sleep(delay);
const path = join(folder, url.pathname === '/' ? 'seats.html' : url.pathname);
if (!path.startsWith(folder)) return res.writeHead(403).end();
try {
const readStart = performance.now();
const body = await readFile(path);
const read = (performance.now() - readStart).toFixed(1);
res.writeHead(200, {
'Content-Type': TYPES[extname(path)] ?? 'application/octet-stream',
// Tells the browser where the server spent its time on this response.
'Server-Timing': `delay;dur=${delay}, read;dur=${read};desc="read file"`,
});
res.end(body);
} catch {
res.writeHead(404).end('Not found');
}
}
Start the server and open http://localhost:8080/show.html. On the laptop with no throttling, the runs behind this module measured LCP at 68 and 80 ms in two loads. The picture arrived 43 to 49 ms after the start, because on localhost every file arrives almost at once.
Now set the phone profile from Module 1: 412 × 823 with touch, device pixel ratio 1, Slow 4G, 6x CPU, cache off. Reload, and paste this snippet into the Console. It prints when each file started and whether it blocked rendering, the server’s timing for the HTML, and each LCP candidate split into parts this module explains next.
const { onLCP } = await import('/vendor/web-vitals.attribution.js');
const ms = (n) => `${Math.round(n)} ms`;
for (const r of performance.getEntriesByType('resource')) {
console.log(`${r.renderBlockingStatus.padEnd(12)} starts ${ms(r.startTime).padStart(7)} ${new URL(r.name).pathname}`);
}
const timing = performance.getEntriesByType('navigation')[0].serverTiming;
console.log('Server-Timing:', timing.map((t) => `${t.name} ${t.duration} ms`).join(', '));
onLCP(({ value, attribution: a }) => {
console.log(`LCP ${ms(value)}, ${a.url ? new URL(a.url).pathname : a.target}:`,
`TTFB ${ms(a.timeToFirstByte)}, load delay ${ms(a.resourceLoadDelay)},`,
`load duration ${ms(a.resourceLoadDuration)}, render delay ${ms(a.elementRenderDelay)}`);
}, { reportAllChanges: true });
It imports the same web-vitals attribution build that vitals.js loaded, so it costs no extra request. reportAllChanges makes onLCP report every candidate, not only the final value.
Here’s the output of one run, in headless Chrome 157 on the 2019 laptop from Modules 1 and 2. Your numbers will differ.
blocking starts 613 ms /show.css
blocking starts 616 ms /analytics.js
blocking starts 617 ms /show.js
non-blocking starts 617 ms /vitals.js
blocking starts 1188 ms /styles.css
non-blocking starts 1853 ms /stadium.jpg
non-blocking starts 1854 ms /vendor/web-vitals.attribution.js
Server-Timing: delay 0 ms, read 0.5 ms
LCP 1864 ms, html>body>main>p: TTFB 564 ms, load delay 0 ms, load duration 0 ms, render delay 1300 ms
LCP 6436 ms, /stadium.jpg: TTFB 564 ms, load delay 1289 ms, load duration 4567 ms, render delay 16 ms
The picture’s request started at 1.85 s, three times later than the HTML’s first byte. LCP was 6.4 s, and the first LCP candidate, a paragraph of text, was painted at 1.86 s. That matches Leo’s bus ride, with the text first and a long wait for the picture.
The lab’s 6.4 s is worse than the field’s 4.1 s. The lab loads with an empty cache on a slow network every time, and many buyers didn’t. But it shows the same symptom, which is what a lab profile is for (Module 1).
How a first load spends its time
The snippet printed four numbers for each candidate. They’re the four parts of LCP, and they are the map for the rest of this module.
LCP has four parts
Every LCP that is an image splits into four parts, with no gap and no overlap between them (web.dev, optimize LCP):
- Time to first byte (TTFB): from the start of the load until the first byte of the HTML arrives.
- Resource load delay is the time from TTFB until the browser starts to request the LCP resource.
- Resource load duration is the time that request takes, until the last byte of the resource arrives.
- Element render delay is the time from the end of that download until the LCP element is painted.
When the LCP element is text in a system font, it needs no resource, so the two resource parts are 0. That’s what the paragraph’s line in the output shows. Figure 1 draws the four parts for the slow load, from a run that measured LCP at 6,448 ms.
start LCP
|-- TTFB --|-- load delay --|---- load duration ----|-- render delay --|
564 ms 1,304 ms 4,566 ms 14 ms
^ ^ ^ ^
HTML's first byte request for last byte of picture
stadium.jpg stadium.jpg painted
starts arrives
Figure 1: on the show page, LCP is 9% TTFB, 20% waiting to start the download and 71% downloading.
web.dev gives a rough target: about 40% of LCP for TTFB, about 40% for the download, and under 10% for each delay. It calls these guidelines, not rules. Its point is that a good LCP spends its time loading the HTML and the image, not waiting.
Each part has its own kind of fix. A long TTFB points to the server and the network. A long load delay means the browser found the resource late or put it behind other requests.
A long load duration means the file is large or the network is slow. A long render delay means something kept the browser from painting, such as a busy main thread. The DevTools LCP breakdown insight shows the same four parts under the same names (Chrome for Developers).
Rule: Work on the largest part of LCP first, then read all four parts again, because a fix can move time from one part to another.
Two parsers find the requests, and each request gets a priority
The browser has two ways to find the files a page needs. The main HTML parser builds the DOM, and it stops when it reaches a script that must run before parsing can go on. The preload scanner is a second parser that reads ahead in the raw HTML while the main parser is stopped. It starts requests for the URLs it finds (web.dev, preload scanner).
The preload scanner reads only HTML. So it can’t find an image that a script inserts, a CSS background image, an image whose URL is in data-src, or a font that a stylesheet names. Those wait until the CSS or JavaScript that names them has arrived and run.
Chrome also gives each request a priority, which decides the order when several requests compete. DevTools shows five levels: Highest, High, Medium, Low and Lowest (DevTools source).
The HTML and the stylesheets in <head> start at Highest. Images start at Low and rise to High once layout shows they’re in the viewport. Since Chrome 117 (2023), the first five large images start at Medium (web.dev, Fetch Priority).
Figure 2 shows the priorities Chrome 157 gave the show page’s picture in the runs behind this module, for each way of writing it.
| How the page asks for the picture | Initial priority | Final priority | Request starts |
|---|---|---|---|
<img loading="lazy"> |
Low | High | 1,847 to 1,870 ms |
<img> |
Medium | High | 609 to 619 ms |
<img fetchpriority="high"> |
High | High | 609 to 615 ms |
CSS background-image |
Low | High | 1,203 to 1,214 ms |
CSS background, plus <link rel="preload" as="image"> |
Low | High | 603 to 612 ms |
CSS background, plus the same preload with fetchpriority="high" |
High | High | 602 to 605 ms |
Figure 2: the preload scanner starts the picture at about 0.6 s, unless lazy loading or CSS hides it. Three runs each, phone profile.
The first row answers the prediction. A loading="lazy" image is in the HTML, so the preload scanner sees it.
But lazy loading tells the browser to wait until layout shows the image is near the viewport. Layout needs the CSS, so the request waits for the stylesheets. So lazy loading is a good default for images below the first screen, but the wrong one for the picture at the top.
What stops the first paint
The browser doesn’t paint until it has every stylesheet in <head>. A render-blocking resource is one the browser must have before it paints anything; stylesheets in <head> are render-blocking (MDN, critical rendering path). Without them, the first paint would be unstyled and would change as soon as the CSS arrived.
A script is different. A parser-blocking script is one that stops the HTML parser until it has downloaded and run, because it may change the document that comes after it. A classic <script src> without async or defer is parser-blocking (MDN, <script>). In <head>, it also blocks rendering, because the parser can’t reach the <body> that the first paint would show.
Figure 3 compares the ways to load a script.
| Script | Downloads | Runs | Blocks the parser |
|---|---|---|---|
<script src> |
when found | as soon as it arrives | yes |
<script src async> |
in parallel with parsing | as soon as it arrives, in any order | only while it runs |
<script src defer> |
in parallel with parsing | after parsing, before DOMContentLoaded, in document order |
no |
<script type="module"> |
in parallel, with its imports | like defer; defer has no effect on it |
no |
Figure 3: only the plain classic script stops the parser while it downloads. Source: MDN, <script>.
The snippet’s first column comes from renderBlockingStatus on each resource timing entry. Chrome added it in version 107; Firefox and Safari don’t report it, so it’s a Chrome-only check. A page can also mark an element as render-blocking on purpose with blocking="render" (Chrome 105, Safari 18.2, not Firefox).
A chain adds a full request for every link
Some requests can start only after another one has finished. In the show page, the browser learns about styles.css only when it reads show.css, because the @import is inside it. That’s a request chain: HTML, then show.css, then styles.css.
On the phone profile, every request pays about 0.56 s of added latency before its first byte (Module 1). So each link in a chain adds at least that much, whatever the file’s size. The DevTools Network dependency tree insight draws these chains for the requests it counts as critical: those that are render-blocking or high priority (Chrome for Developers). Figure 4 is the tree it drew for one trace of the show page.
show.html 0.63 s
+-- show.css 1.18 s
| +-- styles.css 1.76 s (from the @import)
+-- show.js 1.20 s
+-- analytics.js 1.19 s
+-- vitals.js 1.21 s
+-- web-vitals.attribution.js 2.63 s longest chain
times: when each request finished, from the start of the load
Figure 4: two chains hang under the HTML; one delays the first paint and the other doesn’t.
The longest chain is the measuring code. vitals.js imports the web-vitals library, which the browser finds only after vitals.js arrives. The chain that matters for the first paint is the CSS one, because both of its files are render-blocking. The walkthrough comes back to this difference.
Find the cause in the waterfall and the trace
The steps below follow one load of the show page on the phone profile, with the files above.
-
Set up the Network panel. Keep “Disable cache” checked. Right-click the table header and add the Priority column; the Initiator column is on by default. Turn on Big request rows in the panel settings, and the Priority column shows the initial priority below the final one (Network reference). You can also add a Render-blocking column.
-
Read the waterfall. Reload. Figure 5 is the page-load timeline of this course, drawn from one run, with a row for the four LCP parts added.
vitals.jsand the library it loads are left out.
time (s) 0 1 2 3 4 5 6
| | | | | | |
show.html ======
show.css ======
styles.css ======
analytics.js ======
show.js ======
stadium.jpg =============================================
LCP parts [TTFB][ load delay][ resource load duration, 4.57 s------------]|
^ TTFB 0.56 s
^ FCP 1.88 s (text)
LCP 6.45 s (stadium.jpg) ^
NEW: the LCP parts row. The render delay, 14 ms, is the | at the end.
Figure 5: the picture waits for the stylesheet chain, then takes 4.6 s to download.
Three things stand out. styles.css starts only when show.css ends. The picture starts only after styles.css ends. And the picture’s bar is the longest on the page by far.
Pause and predict. The HTML’s first byte arrived at 0.56 s, and the picture is in that HTML. Why does its request start at 1.87 s?
Answer
The picture has loading="lazy", so the browser waits for layout to decide whether it’s near the viewport. Layout needs the CSS, and the last stylesheet, styles.css, arrived at 1.75 s because of the @import chain. The request then starts at Low priority and rises to High when layout puts it in the viewport.
-
Follow the initiators. Hold Shift and hover over
styles.css. Its initiator,show.css, turns green, and the requests that depend on it turn red. The Initiator column forstadium.jpgsays Parser. So the HTML named the picture, and the browser chose to wait. -
Record the load. In the Performance panel, click Record and reload. The trace engine’s insights for one recording of this load were:
- LCP breakdown: LCP 6,463 ms. TTFB 564 ms, resource load delay 1,311 ms, resource load duration 4,571 ms, element render delay 16 ms.
- LCP request discovery failed two of its three checks: “fetchpriority=high should be applied”, and “LCP resources shouldn’t use loading=lazy”. It passed “Request is discoverable in initial document” (Chrome for Developers).
- Render-blocking requests listed
show.js,analytics.js,show.cssandstyles.css, each about 0.58 s long. - Network dependency tree drew Figure 4, with a longest chain of 2,626 ms.
- Improve image delivery said
stadium.jpgis 1600 × 900 and shown at 380 × 214, and could be 664 KB smaller at the right size.
These come from running the DevTools trace engine on a recording made through the DevTools Protocol, as in Module 2.
- Pick the order. The LCP parts say what to fix first: the download (4.6 s), then the late start (1.3 s). FCP depends on the render-blocking files, which the stylesheet chain makes late.
Pause and predict. The longest chain in Figure 4 is vitals.js and its library, 2.63 s. Should it be the first thing to fix?
Answer
No. Neither file blocks rendering, and neither is the LCP resource, so the chain delays neither FCP nor LCP. The insight counts module scripts as critical because they load at High priority. Making the chain shorter also has a cost, measured in the fix section below.
Rule: An insight points at a request; the LCP parts and the render-blocking list tell you whether that request is on the path to the paint.
The fixes, one change at a time
Each fix below changes one thing and was measured three times on the phone profile, alternating with the version before it. The numbers are from one laptop and one day, so yours will differ.
Fix 1: let the preload scanner start the picture
Remove loading="lazy" from the picture and give it a fetch priority:
<img src="/stadium.jpg" fetchpriority="high" alt="The stadium, with the stage at the north end">
fetchpriority is an HTML attribute that tells the browser how important a request is compared with other requests of the same type: high, low or auto (HTML Standard). It’s a hint, so the browser may still order requests its own way.
Resource load delay fell from 1,285–1,307 ms to 46–52 ms, and LCP from 6,424–6,460 ms to 5,232–5,240 ms. The picture now starts at 0.61 s, with the CSS and the scripts. Figure 6 shows the same timeline with only the picture’s row changed.
time (s) 0 1 2 3 4 5 6
| | | | | | |
show.html ======
show.css ======
styles.css ======
analytics.js ======
show.js ======
stadium.jpg ============================================== NEW
^ TTFB 0.56 s
^ FCP 1.86 s
LCP 5.23 s ^
Figure 6: without lazy loading, the picture starts with the first wave of requests.
But fetchpriority didn’t cause that gain. A plain <img>, without lazy loading and without the attribute, gave LCP of 5,236–5,244 ms. It started at Medium and rose to High, at the same moment.
On this page nothing competes with the picture. The other files are small, and HTTP/1.1 opens up to six connections per origin. A priority only matters when there’s a queue to reorder.
web.dev reports a case with a queue: Google Flights moved LCP from 2.6 s to 1.9 s by adding fetchpriority="high" to its main image (web.dev). The same page lists the costs. Marking more than one or two images high stops helping, and a CDN may not follow the priorities. Use fetchpriority="low" for images that start hidden, such as the later slides of a carousel.
Cost: none for the top image. Keep loading="lazy" on images further down the page, where it saves bytes the buyer may never need. A study of field data from 2021 found pages that lazy-loaded their LCP image had a worse LCP at the median, 3,546 ms against 2,922 ms. That’s a correlation, but the lab shows the mechanism (web.dev, LCP and lazy loading).
When the HTML does not name the resource: preload and preconnect
The fix above works because the picture is an <img> in the HTML. If it were a CSS background, the preload scanner couldn’t see it. One variant of the show page had the stylesheets already linked as in Fix 2 below, and the picture as a background-image. It started the picture’s request at 1.20 s, after the stylesheets, and LCP was 5,784–5,808 ms.
preload is a <link rel="preload"> element that tells the browser to fetch a resource now, because the page will need it soon; it fetches and caches, and runs nothing (MDN). It needs an as value, such as image, style or font.
<link rel="preload" as="image" href="/stadium.jpg" fetchpriority="high">
With that line in <head>, the background variant started the picture at 0.60 s, at High, and LCP fell to 5,232–5,236 ms, the same as the <img>. Without fetchpriority="high", the preload started at Low. It made no difference here, but it can on a page with a queue.
Preload has three costs:
- It takes bandwidth from what the parser found. A preload for the
web-vitalslibrary makes the chain in Figure 4 one link shorter. It started the library at 0.6 s instead of 1.3 s. LCP went from 1,440–1,492 ms to 1,536–1,552 ms, because the library now shared the slow network with the picture. That test usedrel="modulepreload", the version of preload for module scripts, on the page after Fix 4. - An unused preload wastes its bytes. Chrome prints a warning in the Console when a preloaded resource isn’t used within a few seconds of the load event.
- A preload ties the HTML to a file name. When the file changes, the preload must change with it.
preconnect is a <link rel="preconnect"> element that opens the connection to another origin early (the DNS lookup, the TCP connection and the TLS handshake) before any request for it (web.dev). It helps when the LCP resource comes from another origin, such as an image CDN.
<link rel="preconnect" href="https://images.example">
Preconnect only to the one or two origins that matter. Each extra preconnect costs bandwidth, for example for the TLS certificate, and can delay other requests. A preconnected connection that is unused for 10 seconds is closed again.
A font origin needs crossorigin on the preconnect. The Network dependency tree insight lists the origins a page preconnected to and suggests candidates. It warns about more than four. For the show page, it listed neither.
This lab can’t show what preconnect saves. The lab server runs on your own machine, so a connection takes almost no time. DevTools throttling works per request. Lighthouse’s documentation calls it request-level throttling, and says real latency acts at the packet level (Lighthouse throttling). So measure a preconnect on a real network, with a tool such as WebPageTest below.
Fix 2: break the stylesheet chain
Remove the @import line from public/show.css, and link both stylesheets from the HTML, base styles first:
<link rel="stylesheet" href="/styles.css">
<link rel="stylesheet" href="/show.css">
The preload scanner now finds both files at once. FCP fell from 1,856–1,912 ms to 1,308–1,332 ms. LCP stayed at 5,232–5,252 ms, because the picture hadn’t waited for the CSS since Fix 1. So the text appears about half a second sooner, but the picture is as slow as before.
Cost: one more request in the HTML. Over HTTP/1.1, each parallel request needs its own connection, up to six per origin.
One alternative is to merge the two files, but then one page’s change makes the cache throw away all the CSS. Another is to inline the first screen’s CSS in the HTML. Chrome’s documentation calls inlining an advanced technique that can cause bugs (Chrome for Developers).
Fix 3: defer show.js, and why nothing changed
show.js only shows a button after parsing, so nothing on the first paint needs it. Add defer:
<script src="/show.js" defer></script>
Pause and predict. show.js was one of four render-blocking requests, each about 0.58 s. How much sooner will the first paint be?
Answer
Not measurably. FCP was 1,292–1,300 ms, against 1,308–1,332 ms before. show.js was blocking, but it arrived at about 1.2 s, in the same wave as analytics.js, which still blocks. The paint waits for the last blocker, and removing one of two blockers that arrive together saves nothing.
But the change still helps. show.js no longer appears in Render-blocking requests, and Chrome now requests it at Low priority, so it stops competing with the picture. It finished at 1.78 s instead of 1.20 s. FCP will move when Module 7 deals with analytics.js.
Cost: a deferred script runs after parsing, so it can’t write into the document as it’s parsed. Code that must run before the first paint, such as setting a theme class, has to stay a blocking script or move inline.
Fix 4: a file sized for the screen
After Fixes 1 to 3, the LCP parts were TTFB 564 ms, load delay 47 ms, load duration 4,606 ms and render delay 16 ms. The download is now 88% of LCP. The picture is 1600 px wide, and the phone draws it 380 px wide.
A responsive image is an <img> that lists files of different widths in srcset and its display width in sizes, so the browser can pick a file before layout (MDN). Make smaller copies of the picture (the lab shows how), then list them:
<img src="/stadium.jpg" fetchpriority="high"
srcset="/stadium-400.jpg 400w, /stadium-800.jpg 800w, /stadium-1200.jpg 1200w, /stadium.jpg 1600w"
sizes="calc(100vw - 32px)" alt="The stadium, with the stage at the north end">
400w means “this file is 400 px wide”. sizes says the image will be the viewport’s width minus the 16 px padding on each side, which matches the CSS. The preload scanner reads both attributes, so the right file still starts at once, before any CSS arrives.
The browser divides each file’s width by the sizes width to get the file’s pixel density. Then it takes the smallest file whose density is at least the screen’s device pixel ratio (HTML Standard, selecting an image source). On the phone profile (412 px wide, device pixel ratio 1), the image is 380 px wide. stadium-400.jpg has a density of 400 / 380 = 1.05, so the browser picks it: 41 KB instead of 704 KB.
LCP fell from 5,232–5,264 ms to 1,444–1,452 ms. Load duration fell from about 4,606 ms to 819–829 ms.
But most phones have a device pixel ratio above 1, and there the browser picks a larger file. Figure 7 repeats the measurement at three ratios.
| Device pixel ratio | No srcset |
srcset, JPEG |
<picture>, AVIF first |
|---|---|---|---|
| 1 | 5,232–5,264 ms (1600 px, 704 KB) | 1,444–1,452 ms (400 px, 41 KB) | 1,320–1,356 ms (400 px, 14 KB) |
| 2 | 5,240–5,244 ms (1600 px, 704 KB) | 2,288–2,296 ms (800 px, 174 KB) | 1,532–1,536 ms (800 px, 55 KB) |
| 2.625 | 5,232–5,252 ms (1600 px, 704 KB) | 3,632–3,636 ms (1200 px, 416 KB) | 2,308–2,320 ms (1200 px, 176 KB) |
Figure 7: a denser screen picks a larger file, and a smaller format matters most there. LCP from three runs each, phone profile with the ratio changed; the file chosen in parentheses.
Check the device pixel ratio in the device toolbar. If it’s 2, your browser picks stadium-800.jpg; set it to 1 to compare with the numbers above.
Fix 5: a smaller format
The last column of Figure 7 adds AVIF files. AVIF is an image format that compresses pictures better than JPEG; web.dev reports savings above 50% “in some cases” (web.dev). For this picture, the AVIF files were 14, 55, 176 and 448 KB, against 41, 174, 416 and 704 KB for the JPEG files of the same widths. A <picture> element offers AVIF to browsers that support it and keeps the JPEG for the rest:
<picture>
<source type="image/avif"
srcset="/stadium-400.avif 400w, /stadium-800.avif 800w, /stadium-1200.avif 1200w, /stadium.avif 1600w"
sizes="calc(100vw - 32px)">
<img src="/stadium.jpg" fetchpriority="high"
srcset="/stadium-400.jpg 400w, /stadium-800.jpg 800w, /stadium-1200.jpg 1200w, /stadium.jpg 1600w"
sizes="calc(100vw - 32px)" alt="The stadium, with the stage at the north end">
</picture>
The browser takes the first <source> whose type it supports, then picks a width from that source’s srcset (MDN). The <img> still carries alt, fetchpriority and the layout. Add '.avif': 'image/avif' to the TYPES table in server.js, so the files go out with the right content type.
On the phone profile, LCP went from 1,444–1,452 ms to 1,320–1,356 ms. At a ratio of 2.625, it went from 3,632–3,636 ms to 2,308–2,320 ms. The trace’s Improve image delivery insight passed.
The costs of Fixes 4 and 5:
- Files to make and keep. Each picture is now eight files. A real site makes them in its build or upload step. An image CDN can resize on request instead, but it’s one more service to pay for and one more origin to connect to.
sizesmust match the CSS. If the layout changes andsizesdoesn’t, the browser picks a file for the wrong width.sizes="auto"lets the browser use the laid-out width, but only for lazy-loaded images, so not for the LCP image. It works in Chrome 126 and Firefox 150, and only partly in Safari.- Encoding. AVIF files need an encoder that supports them, and older browsers need the JPEG fallback. WebP has been widely available for longer (since 2023), and JPEG XL is decoded since Chrome 155 (2026), not yet in all browsers (Chrome blog).
Figure 8 is the page-load timeline after all five fixes, from one run.
time (s) 0 1 2 3 4 5 6
| | | | | | |
show.html ======
styles.css ======
show.css ======
analytics.js ======
show.js ============ (defer)
stadium-400 ======= NEW (.avif)
^ TTFB 0.56 s
^ FCP 1.33 s, LCP 1.34 s (stadium-400.avif)
Figure 8: the picture arrives with the CSS, so the first paint and LCP are nearly the same frame.
That run’s parts were TTFB 564 ms, load delay 62 ms, load duration 676 ms and render delay 42 ms. So TTFB and the download are now most of LCP, the shape web.dev describes.
The seat map: when the download is fixed, the main thread is left
Module 2 handed this module a problem. On the seat map, 4.5 s of LCP was stadium.jpg downloading. Give the seat map’s <img> the same <picture> markup, without fetchpriority.
Pause and predict. On the show page, the same change saved about 3.9 s. How much will it save on the seat map?
Answer
Far less. In four runs each, alternating, LCP went from 5,376–5,912 ms to 4,856–5,308 ms. Load duration fell from about 4,520 ms to 676–689 ms, and element render delay grew from 240–785 ms to 3,570–4,003 ms. The picture arrives at 1.3 s, and then waits for the main thread.
Figure 9 shows why, from a recorded run. Recording slows the page (Module 2), so its LCP of 6.40 s is later than the unrecorded runs.
time (s) 0 1 2 3 4 5 6
| | | | | | |
seats.html ======
styles.css ======
analytics.js ======
seats.js ======
stadium-400 ======= NEW (.avif)
main thread [== JS, 1.66 s =][====== rendering, 3.31 s ======]
^ image downloaded 1.31 s
LCP 6.40 s (stadium-400.avif) ^
Figure 9: the picture is ready at 1.3 s, but the main thread builds and lays out 60,000 seats before it can paint it.
The seat map’s LCP is now an element render delay, and the cause is the main thread, which Modules 5 and 6 work on. The fix moved time from one part to another, and the parts now name the next problem.
Before and after
Figure 10 puts the show page’s steps side by side. Every row is three runs on the phone profile at a device pixel ratio of 1.
| Step | Change | FCP | LCP | Largest LCP part |
|---|---|---|---|---|
| Before | loading="lazy", @import, blocking show.js |
1,860–1,880 ms | 6,424–6,460 ms | load duration, 4.6 s |
| 1 | no lazy loading, fetchpriority="high" |
1,856–1,912 ms | 5,232–5,240 ms | load duration, 4.6 s |
| 2 | both stylesheets linked from the HTML | 1,308–1,332 ms | 5,232–5,252 ms | load duration, 4.6 s |
| 3 | defer on show.js |
1,292–1,300 ms | 5,232–5,244 ms | load duration, 4.6 s |
| 4 | srcset and sizes |
1,296–1,324 ms | 1,444–1,452 ms | load duration, 0.8 s |
| 5 | <picture> with AVIF |
1,304–1,328 ms | 1,320–1,356 ms | load duration, 0.7 s (TTFB 0.56 s) |
Figure 10: two image fixes took LCP from 6.4 s to 1.3 s; the CSS fix took FCP from 1.9 s to 1.3 s.
None of these fixes changed CLS. The picture still has no width or height, and its arrival still moves the text below it. The layout shift was 0.098 on the show page and 0.190 on the seat map, before and after. Module 6 fixes that.
103 Early Hints: starting before the HTML exists
After the fixes, TTFB is almost as large as the download in the show page’s LCP. During those 0.56 s, the browser has nothing to read. On a real server, part of that time is the server building the page.
103 Early Hints is an HTTP response with status 103 that a server sends before the final response. Its Link headers let the browser preconnect or preload while the server is still working (MDN, RFC 8297). Figure 11 shows the exchange, with the course’s request symbols.
(Buyer's phone) --> [CDN] --> [TinyTickets web app] --> [[PostgreSQL]]
<-- 103 Early Hints
Link: </stadium-400.avif>; rel=preload; as=image NEW
(the browser starts the picture's request here)
... the app runs the show query ...
<-- 200 OK, the HTML
Figure 11: the browser uses the server’s thinking time to start the picture.
Chrome supports preload and preconnect in a 103 since version 103 (2022), for page loads only (Chrome for Developers). Firefox supports preconnect from 103 since version 120 and preload since 123. Safari 17 and later apply preconnect from a 103 but not preload. Chrome and Safari use a 103 only over HTTP/2 or HTTP/3.
The costs and limits:
- The hints are guesses. A 103 is sent before the server knows the final response, and the browser must not treat it as authoritative. A preload for the wrong file wastes bandwidth.
- Cacheable files only. Chrome loads a hinted resource again if it isn’t cacheable, and drops all hints after a cross-origin redirect. Browsers use only the first 103.
- It needs HTTP/2 or later, usually from the CDN. The lab server speaks HTTP/1.1, so this lab can’t show it.
Chrome removed HTTP/2 server push in version 106 (2022), and points to 103 Early Hints and preload in its place. Push sent the files themselves without being asked; about 1.25% of HTTP/2 sites used it, and it often made pages slower (Chrome for Developers).
Server-Timing: where TTFB goes to the server
TTFB isn’t all server time. It includes redirects, the DNS lookup, the connection and TLS, and the request’s trip to the server (web.dev, TTFB). So if you want to know how much belongs to the server, ask the server.
Server-Timing is an HTTP response header in which the server lists named durations, such as a database query. The browser shows them in DevTools and to the page’s JavaScript (W3C Server Timing). Each entry has a name, an optional dur in milliseconds and an optional desc.
The lab server has sent this header since you built the show page: delay is the ?delay= value, and read is the time to read the file from disk. The snippet’s Server-Timing line printed delay 0 ms, read 0.5 ms for a TTFB of 564 ms. So the lab’s TTFB is all network, almost exactly the 562.5 ms that Slow 4G adds to each request.
Cost: the header is public. Anyone who opens DevTools on your page reads its names and numbers, so never put internal host names, user data or secrets in it. For a cross-origin request, the page’s JavaScript sees the entries only if the response also has a Timing-Allow-Origin header.
On the production show page, Maya added Server-Timing: db;dur=…;desc="show query" next to the timings her server traces already recorded. The query took about 140 ms of the page’s TTFB. This course stops at that number. Why a query or a server is slow is the subject of the Performance and Cost course.
Confirming it in the field
Maya shipped Fixes 1 to 5 on the show page template the same week. Her endpoint compared the week after with the week before. On phones, the show pages’ 75th percentile LCP fell from 4.1 s to 2.3 s, over 1,190 page loads. CrUX would show the change only as its 28-day window moved past the release.
The field’s 2.3 s is higher than the lab’s 1.3 s. Real phones have screens with a ratio of 2 or more, so they pick the 800 or 1200 px files (Figure 7). Their networks vary, and analytics.js still blocks the first paint.
In Firefox and Safari
fetchpriorityworks in Chrome since 101 (2022), Safari since 17.2 (December 2023) and Firefox since 132 (October 2024). It has been Baseline since October 2024 (MDN).renderBlockingStatus, used by the snippet, is Chrome-only. In Firefox and Safari, check the waterfall by hand.- 103 Early Hints: see the support list in the 103 section above. Safari ignores
preloadhints. - LCP is measured in Firefox since 122 and in Safari since 26.2, but CrUX field data comes only from Chrome (web.dev, 2025-12-17).
What changed recently
- Chrome 106 (2022): HTTP/2 server push removed; use preload or 103 Early Hints (Chrome for Developers).
- Chrome 117 (2023): the first five large images start at Medium priority, not Low (web.dev).
- Firefox 132 (October 2024):
fetchpriorityworks in all three engines. - Lighthouse 13 (October 2025): the old audits became insights, shared with the Performance panel.
critical-request-chainsanduses-rel-preconnectbecamenetwork-dependency-tree-insight,render-blocking-resourcesbecamerender-blocking-insight, andlcp-lazy-loadedandprioritize-lcp-imagebecamelcp-discovery-insight. It reached stable Chrome in Chrome 143 (Chrome for Developers). Older articles still use the old names. - Safari 26.2 (December 2025): reports LCP, so LCP works in all three engines.
- 2026: AVIF became Baseline widely available on 2026-07-25, and Chrome 155 started decoding JPEG XL (Chrome blog, 2026-10-06).
Online tools for this step
These three tools load a page from their own servers, so they can’t test the lab app on localhost or any private page. Use them on public pages only, and use DevTools for the lab and for anything behind a login.
WebPageTest loads a page from test locations around the world and draws a full waterfall, with the DNS, connection and TLS time of every request. It adds a filmstrip and a video of the load. It’s run by Catchpoint, now part of LogicMonitor, and its code is public under the Polyform Shield license.
- Data: lab, on real devices and connection profiles you choose.
- Limit: the free plan gives 150 test runs a month, 3 runs per test, 30 locations and 60 days of history. Private tests are only in the paid plans (pricing), so treat a free test’s results as public.
- When DevTools is better: for the lab app, for private pages, and when you change one thing and test again many times.
DebugBear’s free speed test runs one lab test of a URL from “Mobile + US East” or “Desktop + US East”, and more locations after sign-up.
- Data: lab, on a throttled real connection rather than simulated throttling, with a full Lighthouse report, an LCP breakdown, render-blocking and LCP image checks. It also shows the URL’s CrUX field data.
- Limit: two locations without an account; public pages only.
- When DevTools is better: when you need to change one thing and test again many times, or test a page that isn’t public.
Request Map Generator, by Simon Hearne, takes one URL and draws every request as a node, grouped by domain, with the bytes and time per domain.
- Data: lab, one load.
- Limit: it’s a map of who the page calls, not a waterfall of when. It can’t show a chain’s timing or a priority.
- When DevTools is better: for timing, priorities and anything about LCP. The map is useful to see how many third-party domains a page depends on.
Check yourself
Debugging scenario
Suppose a festival organizer’s page on TinyTickets has a poor LCP on phones. Its LCP element is a <div class="hero"> whose picture is a CSS background. On the phone profile, one run gives:
- LCP breakdown: LCP 3,600 ms. TTFB 600 ms, resource load delay 1,250 ms, resource load duration 1,700 ms, element render delay 50 ms.
- Waterfall:
festival.htmlends at 0.60 s.main.cssruns from 0.62 to 1.20 s.hero.cssruns from 1.21 to 1.79 s, and its Initiator ismain.css.hero.jpg(200 KB) runs from 1.85 to 3.55 s; its priority is Low, then High. - FCP is 1.85 s.
What causes the late start, which two changes would you make first, and what would you expect LCP to become?
Hint 1
Who names hero.jpg, and can the preload scanner see it?
Hint 2
Count the links between the HTML and the picture. Each one on this profile costs about 0.58 s.
Answer
The picture is a CSS background named in hero.css, which main.css imports. That’s a chain of three links: HTML, main.css, hero.css, then the picture. The preload scanner can’t see a CSS background, and the browser finds it only after both stylesheets arrive and it matches the rule. That’s the 1,250 ms load delay, and it starts at Low, as a CSS background does.
First, add <link rel="preload" as="image" href="/hero.jpg" fetchpriority="high"> to the HTML, or turn the picture into an <img> with fetchpriority="high". Then its request starts with the first wave, at about 0.62 s, and at High. Second, link hero.css from the HTML instead of importing it, so FCP no longer waits for a second stylesheet.
Expect LCP near 600 + about 50 + 1,700 + 50 ms, about 2.4 s, a little more because the picture now shares the network with the CSS. The largest part is then the 1.7 s download, so the next fix is a smaller file: srcset and sizes, and AVIF.
Review questions
- A page’s LCP is 3.0 s: TTFB 0.5 s, load delay 0.1 s, load duration 2.3 s, render delay 0.1 s. Which kind of fix comes first, and why not preload?
- The LCP image is in the HTML with
loading="lazy". Why does its request start late, and what does it wait for? - A blocking script in
<head>and the last stylesheet both arrive at 1.2 s. You adddeferto the script. Does FCP change, and why? - When does
fetchpriority="high"on the LCP image change LCP, and what does a preload cost even when it helps? - A phone has a device pixel ratio of 3,
sizesgives 360 px, andsrcsetoffers 400w, 800w and 1200w. Which file does it get? And what doesServer-Timingtell you that TTFB doesn’t?
Answers
- Make the file smaller, because the download is 77% of LCP. Preload moves a request’s start, and this request already starts within 0.1 s.
- Lazy loading makes the browser wait for layout to decide whether the image is near the viewport. Layout waits for the render-blocking CSS, so the image starts after the last stylesheet arrives.
- No. The paint waits for the last render-blocking file, and the stylesheet still arrives at 1.2 s.
- When other requests compete with it, so there’s a queue to reorder. A preload takes bandwidth from the requests the parser found, and wastes its bytes if the page doesn’t use the file.
- The 1200w file: 800 / 360 is 2.2, below 3, and 1200 / 360 is 3.3.
Server-Timingnames how long the server’s own steps took; TTFB also includes redirects, DNS, the connection, TLS and the network.
Lab: find and fix the late picture
Time: about 15 minutes. You need the lab app from Module 2, Chrome and Node.js. The finished code for this module is in the course repository, folder module-03/.
- Add
public/show.html,public/show.cssandpublic/show.jsfrom the start of this module, and theServer-Timingheader toserver.js. Runnode server.js, openhttp://localhost:8080/show.htmlin an Incognito window, and set the phone profile: 412 × 823 with touch, device pixel ratio 1, Slow 4G, 6x CPU, “Disable cache” checked. - In the Network panel, add the Priority column and turn on Big request rows. Predict when
stadium.jpgwill start. Reload, and write down its start time and its two priorities. - Paste the snippet from “Build the show page” into the Console. Write down the four parts of the picture’s LCP.
- In the Performance panel, click Record and reload. In the Insights tab, read LCP breakdown, LCP request discovery, Render-blocking requests and Network dependency tree. Which checks fail?
- Remove
loading="lazy"and addfetchpriority="high". Reload, run the snippet, and compare the load delay. Then move the stylesheets out of the@importchain (Fix 2), and compare FCP in the Performance panel. - Make the smaller files. Copy them from the course repository’s
module-03/public/, or on macOS run this inpublic/. It usessips, which ships with macOS; these commands were tested on macOS 26.7.
for w in 400 800 1200; do
sips -Z $w stadium.jpg --setProperty formatOptions 80 --out stadium-$w.jpg
sips -s format avif -s formatOptions 60 stadium.jpg -Z $w --out stadium-$w.avif
done
sips -s format avif -s formatOptions 60 stadium.jpg --out stadium.avif
- Add
'.avif': 'image/avif'toTYPESinserver.js, and restart it. Replace the<img>with the<picture>from Fix 5. Reload, run the snippet, and compare LCP and its parts with step 3. Read theServer-Timingline.
Results from one run
These come from headless Chrome 157 on a 2019 laptop (Intel Core i7-9750H) through the DevTools Protocol. Your numbers will differ; the order of the parts shouldn’t.
- Step 2:
stadium.jpgstarted at 1,853 ms, at Low, raised to High. - Step 3: LCP 6,436 ms: TTFB 564, load delay 1,289, load duration 4,567, render delay 16 ms.
- Step 4: in a recorded run, LCP request discovery failed “fetchpriority=high should be applied” and “LCP resources shouldn’t use loading=lazy”. Render-blocking requests listed four files, and the network dependency tree’s longest chain was
vitals.jsand its library. - Step 5: load delay 46–52 ms and LCP 5,232–5,240 ms after the first change; FCP 1,308–1,332 ms after the second.
- Step 7, the snippet’s output:
blocking starts 615 ms /styles.css
blocking starts 616 ms /show.css
blocking starts 617 ms /analytics.js
non-blocking starts 617 ms /show.js
non-blocking starts 617 ms /vitals.js
non-blocking starts 617 ms /stadium-400.avif
non-blocking starts 1345 ms /vendor/web-vitals.attribution.js
Server-Timing: delay 0 ms, read 1 ms
LCP 1352 ms, html>body>main>p: TTFB 564 ms, load delay 0 ms, load duration 0 ms, render delay 788 ms
LCP 1372 ms, /stadium-400.avif: TTFB 564 ms, load delay 55 ms, load duration 681 ms, render delay 72 ms
Stretch: turn the picture into a CSS background-image, measure the load delay, then add a <link rel="preload" as="image"> with and without fetchpriority="high", and check both priorities in the Network panel.
Cheat sheet
The slow first load
1. LCP = TTFB + load delay + load duration + render delay; fix the largest
2. Never lazy-load the LCP image; give it fetchpriority="high"
3. The preload scanner reads HTML only: CSS backgrounds and JS images need preload
4. CSS in <head> blocks the paint; a classic script blocks the parser
5. Each link in a request chain costs a full request: link, do not @import
6. The paint waits for the last blocker; removing one of two saves nothing
7. srcset + sizes: smallest file with width / slot >= device pixel ratio
8. Preload and preconnect take bandwidth; use one or two
9. Server-Timing shows the server's share of TTFB; 103 starts work before it
Figure 12 is the whole module in one picture: each part of LCP, and the fixes this module used for it.
LCP = [ TTFB ] + [ load delay ] + [ load duration ] + [ render delay ]
| | | |
103 Early Hints no lazy loading srcset + sizes no render-blocking
Server-Timing: fetchpriority AVIF in <picture> CSS chains; defer
the rest is the preload for CSS (fewer bytes) scripts; a free
server's job or JS images main thread
(Modules 5, 6)
Figure 12: name the largest part first, then pick from the fixes under it.
Next, in Module 4, a buyer goes back from checkout to the seat map and waits for the whole page again. Maya opens the Use efficient cache lifetimes insight, which failed in every trace so far.
Sources
- LCP and its parts: LCP, optimize LCP, TTFB, LCP and lazy loading, LCP and INP are Baseline.
- Discovery and priority: preload scanner, Fetch Priority,
rel=preload, preconnect and dns-prefetch,fetchPriorityon MDN. - Blocking: critical rendering path,
<script>. - Images: responsive images, image performance, JPEG XL in Chrome.
- Early Hints and Server-Timing: 103 on MDN, Early Hints in Chrome, removing HTTP/2 push, RFC 8297, RFC 9114 (HTTP/3), Server Timing.
- DevTools: Network reference, insights for LCP breakdown, LCP request discovery, render-blocking requests, network dependency tree, document request latency, Lighthouse 13, Lighthouse throttling.
- For going deeper: the HTML Standard’s image source selection (section 4.8.4.3.7) and fetch priority attributes; the DevTools trace engine’s insights in
front_end/models/trace/insights/of ChromeDevTools/devtools-frontend, and its priority labels infront_end/ui/legacy/components/perf_ui/NetworkPriorities.ts.