completefrontend
Open lab My progress
THE WEB PERFORMANCE FIELD GUIDE

Adaptive loading

Send a lighter page to slow phones and networks: read Save-Data, the network and device memory, choose on the server with client hints, keep the core.

By the end, you can
  • 01
    Read the signalsRead Save-Data, the network type, the device's memory and its cores, in the page and as request headers, and know how rough each one is.
  • 02
    Let the server chooseAsk for client hints with Accept-CH, know what the first request carries, retry with Critical-CH when it matters, and keep caches right with Vary.
  • 03
    Build a lighter page that still worksKeep what visitors came for, send smaller files, and turn heavy extras into a tap, with a safe choice when a signal is missing.

Ravi's full page on Asha's phone

In lesson 37.1, Ravi learned to see his shop the way Asha's phone sees it. Now he wants to help her phone. Three things work against Asha. Her phone has only 2 GB of memory. Her network is slow. And her data plan is small, so she turned on Data Saver.

Meanwhile, Ravi's Mint tea page has grown. It has a big photo of the tea. Under it, a brewing video plays by itself. The headings use a handwriting font. At the bottom, 50 reviews load at once. On Ravi's laptop, it all feels quick.

So here is the question. Can the page tell that Asha's phone and network are slow, and send her less? It can. Ravi built a second, lighter version of the same page. Here are both, loading on Asha's network, at four moments:

Real frames of Ravi's Mint tea page on Asha's network, at 1,000 ms, 1,500 ms, 2,000 ms, 3,500 ms. Top row, the full page: 1,000 ms, no photo yet, 3 KB so far; 1,500 ms, photo loading, 59 KB so far; 2,000 ms, the photo, 144 KB so far; 3,500 ms, photo, new font, 339 KB so far. Bottom row, the lighter page: 1,000 ms, no photo yet, 3 KB so far; 1,500 ms, the photo, 15 KB so far; 2,000 ms, the photo, 15 KB so far; 3,500 ms, the photo, 15 KB so far.1,000 ms1,500 ms2,000 ms3,500 msFull page339 KBFull page at 1,000 ms: no photo yetno photo yet3 KBFull page at 1,500 ms: photo loadingphoto loading59 KBFull page at 2,000 ms: the photothe photo144 KBFull page at 3,500 ms: photo, new fontphoto, new font339 KBLighter page15 KBLighter page at 1,000 ms: no photo yetno photo yet3 KBLighter page at 1,500 ms: the photothe photo15 KBLighter page at 2,000 ms: the photothe photo15 KBLighter page at 3,500 ms: the photothe photo15 KB
Real frames from the recording, in ms after Asha opened the page. Under each frame: the data that had arrived by then. The lighter page showed its photo at 1,256 ms and stopped at 15 KB. The full page showed its photo at 1,760 ms and went on to 339 KB.

Under each frame is the data that had arrived. Here are the numbers that matter most:

The full page and the lighter pagePop out in the code editor (opens in a new tab)JavaScript
// Ravi's Mint tea page on Asha's network: Slow 4G, CPU 4 times slower.// Each number is the middle of three visits.const pages = [  { page: "Full page", kb: 339, photoAt: 1760, cart: 45 },  { page: "Lighter page", kb: 15, photoAt: 1256, cart: 42 },];for (const { page, kb, photoAt, cart } of pages) {  console.log(`${page}: ${kb} KB, photo at ${photoAt} ms, Add to cart ${cart} ms`);}
  • Lines 1 and 2 are comments. A KB is a kilobyte, about a thousand bytes. A millisecond (ms) is a thousandth of a second.
  • Line 4 is the full page. kb is how much it downloaded. photoAt is when the tea photo was on screen: the page's largest contentful paint, or LCP, from lesson 17.1.
  • cart is how long a tap on Add to cart took, until the next frame. That's its INP, from lesson 26.1.
  • Line 5 is the lighter page. Lines 7 to 9 print one line for each.
  • It prints Full page: 339 KB, photo at 1760 ms, Add to cart 45 ms and Lighter page: 15 KB, photo at 1256 ms, Add to cart 42 ms.

The lighter page downloaded 22 times less. Its photo was on screen 504 ms sooner. And Add to cart was just as quick. Why it matters: Asha got the same tea, the same price and the same button, for a fraction of her data.

Real-life analogyA minibus for a narrow road

A school trip goes to a village with a narrow road and an old bridge. The bus company reads the road sign. It sends a minibus, not a big coach. The children visit the same places. They just travel in a bus that fits the road.

In real life: The narrow road and the old bridge
In JavaScript: Asha's slow network and small phone
In real life: The sign: "narrow bridge ahead"
In JavaScript: Signals such as Save-Data and the device's memory
In real life: The minibus
In JavaScript: The lighter page
In real life: The same stops on the same trip
In JavaScript: What Asha came for: the tea, the price, Add to cart
The main idea

Adaptive loading reads what the browser says about the device, the network and the visitor's wishes. Then it sends a lighter page that still does everything the visitor came for. The signals reach you in two places. Some are request headers, which the server reads before it answers. Others are values the page's script reads. This lesson takes them one at a time.

How the course recorded it

  • Ravi's page: both versions came from a small Node server on the laptop. The server runs Ravi's rule, which this lesson builds.
  • Asha's network and phone: Chrome 157, with DevTools' Slow 4G preset and the CPU 4 times slower, in a window 412 by 480 pixels. One test used DevTools' 3G preset.
  • Asha's Data Saver: Chrome on a laptop has no Data Saver switch. So the recorder added Save-Data: on to every request, and set saveData to true, through the DevTools protocol.
  • A 2 GB phone: Chrome's low-end mode, from lesson 37.1, which reports 2 GB.
  • Asha's taps: mouse clicks, sent through DevTools. Each test ran three times, taking turns. The lesson quotes the middle one.

Save-Data: Asha asks for less

Start with the clearest signal. Asha herself asked for less. On Android, the setting is called Data Saver. Lesson 33.3 showed what Chrome does while it's on. It adds Save-Data: on to its requests, and navigator.connection.saveData becomes true. Ravi used it there to skip his guesses about the next page. That was the sticker on the letterbox: "No flyers, please".

Now Ravi uses the same sticker for the whole page. His server reads it:

The server reads Save-DataJavaScript
// Ravi's server: the lighter page for anyone who asks to save data.const lighter = request.headers["save-data"] === "on";response.setHeader("Vary", "Save-Data");response.end(lighter ? lightHtml : fullHtml);
  • Line 1 is a comment.
  • Line 2 checks the request's Save-Data header. Node gives header names in lower case.
  • Line 3 adds Vary: Save-Data. Lesson 15.1 met Vary. It tells caches that this header changes the answer, so they keep the two pages apart.
  • Line 4 sends the lighter page to anyone who asked to save data, and the full page to everyone else.

Does the server hear about it in time? Yes. On Asha's very first visit, the request for the page already said Save-Data: on. Chrome sends it without being asked (client_hints.cc, lines 23 to 33). So the server sent the lighter page at once: 15 KB instead of 339 KB.

Why it matters: Save-Data is the one signal the server gets on the first request, with nothing to set up. Use it for the page itself.

DevTools' Save-Data menu

How do you test this on a laptop? DevTools' device toolbar has a Save-Data menu, next to the network menu. Its own tooltip says it overrides navigator.connection.saveData on the page (ThrottlingManager.ts). The course made the same change through the DevTools protocol, and watched what reached the server:

What the server saw with the menu onPop out in the code editor (opens in a new tab)JavaScript
// DevTools' Save-Data menu set to on. The first three requests, as the server saw them.const requests = [  { file: "the page", saveData: undefined },  { file: "page.js", saveData: "on" },  { file: "photo-1600.jpg", saveData: "on" },];for (const { file, saveData } of requests) {  console.log(`${file}: ${saveData ?? "no Save-Data"}`);}
  • Lines 3 to 5 are the first three requests, in order.
  • It prints the page: no Save-Data, page.js: on and photo-1600.jpg: on.

The request for the page itself carried nothing. So the server sent the full page. Why? Chrome adds Save-Data to that request from Android's own setting (client_hints.cc, lines 268 to 275). The later requests come from the page, and the page reads DevTools' value (frame_fetch_context.cc, lines 829 to 834).

Why it matters: the menu tests your page's own check, not your server's. To test the server, send the header yourself, or use a real Android phone with Data Saver on.

What the page can read about the network

Not everyone on a slow network turns on Data Saver. Can the page tell the network is slow by itself? Chromium browsers give the page a rough answer.

Real-life analogyA traffic report on the radio

The radio says "heavy traffic on the ring road". It doesn't count the cars. It sums up the last half hour in a few words. It's enough to choose your route.

In real life: "Heavy traffic on the ring road"
In JavaScript: effectiveType, such as "3g"
In real life: The last half hour of cars
In JavaScript: The round trips Chrome saw recently
In real life: Rounded, not counted car by car
In JavaScript: rtt and downlink, rounded
In real life: Changing your route
In JavaScript: Skipping the video on a slow network

The radio is navigator.connection. It comes from the Network Information API. Here is what the page read under DevTools' Slow 4G preset:

Reading the connectionJavaScript
// What the page read under DevTools' Slow 4G preset.const connection = navigator.connection;console.log(connection.effectiveType); // "3g"console.log(connection.rtt);           // 600console.log(connection.downlink);      // 1.5console.log(connection.saveData);      // false
  • Line 3, effectiveType, is the type of connection, as one word: "slow-2g", "2g", "3g" or "4g". Here it's "3g".
  • Line 4, rtt, is the round-trip time Chrome sees: there and back, in ms.
  • Line 5, downlink, is the download speed, in megabits per second.
  • Line 6 is the Save-Data setting again.

Wait: Slow 4G reads as "3g"? Yes. The word doesn't come from the network's name. Chrome picks it from the round-trip time, with three lines (network_quality_estimator_params.h, lines 27 to 32):

Chromium's three lines, as a functionPop out in the code editor (opens in a new tab)JavaScript
function effectiveType(rttMs) {  if (rttMs >= 2010) return "slow-2g";  if (rttMs >= 1420) return "2g";  if (rttMs >= 272) return "3g";  return "4g";} console.log(effectiveType(562.5)); // Slow 4G adds 562.5 msconsole.log(effectiveType(2000));  // 3G adds 2,000 ms
  • Lines 2 to 4 are the lines: 2,010 ms or more is slow-2g, 1,420 ms or more is 2g, and 272 ms or more is 3g.
  • Line 5: anything faster is 4g.
  • Line 8 prints 3g. Slow 4G adds 562.5 ms to each request, which is past the 272 ms line. Line 9 prints 2g for DevTools' 3G preset.

DevTools hands its preset to the page (inspector_network_agent.cc, lines 759 to 777). Chrome then runs those same lines on it (network_state_notifier.cc, lines 226 to 247). The course read the values under each preset, in three new tabs each:

Four presets, three tabs eachPop out in the code editor (opens in a new tab)JavaScript
// What navigator.connection said under each DevTools preset, in 3 new tabs each.const presets = [  { preset: "No throttling", type: "4g", rtt: [100, 100, 100] },  { preset: "Fast 4G", type: "4g", rtt: [200, 150, 150] },  { preset: "Slow 4G", type: "3g", rtt: [600, 600, 550] },  { preset: "3G", type: "2g", rtt: [2200, 1800, 1900] },];for (const { preset, type, rtt } of presets) {  console.log(`${preset}: ${type}, rtt ${rtt.join(", ")} ms`);}
  • Lines 3 to 6 hold what the page read: the type, and the three rtt readings.
  • It prints No throttling: 4g, rtt 100, 100, 100 ms and Fast 4G: 4g, rtt 200, 150, 150 ms. Then Slow 4G: 3g, rtt 600, 600, 550 ms and 3G: 2g, rtt 2200, 1800, 1900 ms.

Why did the same preset read 550 one time and 600 the next? Chrome blurs the numbers on purpose (network_state_notifier.cc, lines 381 to 443):

  • It multiplies the round trip by a number from 0.90 to 1.10. The number comes from the site's name and a secret the browser keeps.
  • It rounds rtt to 50 ms, and stops at 3,000 ms.
  • It rounds downlink to 50 kilobits per second, and stops at 10 megabits per second.

The source code's comments give the reason: to reduce fingerprinting. Fingerprinting is recognising a visitor from many small facts about their device, without a cookie. Rough numbers tell a site less about you.

The connection can also change while the page is open, such as when Asha walks out of her Wi-Fi. Then navigator.connection fires a change event. Move the slider to see where Chrome draws its lines. The lab also reads your own browser:

Playground: from a round trip to a network type
Chromium's lines, as a functionJavaScript
function effectiveType(rttMs) {
  if (rttMs >= 2010) return "slow-2g";
  if (rttMs >= 1420) return "2g";
  if (rttMs >= 272) return "3g";
  return "4g";
}
The rule, for this round trip
  1. effectiveType"3g"
  2. Line it passed272 ms
  3. What rtt can read500 ms to 600 ms
This browser, right now
  1. This browserreading…
Try it yourself
562 ms reads as "3g"

Chrome's lines are 272, 1,420 and 2,010 ms. The rtt a page reads is the round trip times a number from 0.90 to 1.10, rounded to 50 ms, so it can read anywhere from 500 ms to 600 ms.

The left pane is Chromium's rule, written as JavaScript. The lower list is read live from this browser, once, when the lab appears.

Why it matters: effectiveType is a rough guess from recent trips. It's good for choosing extras, such as the video. Firefox and Safari don't have it at all.

Device memory and CPU cores

Asha's phone is slow even on fast Wi-Fi. Lesson 37.1 showed why: a small phone has less memory and a slower chip. The page can read two numbers about the device.

Real-life analogyAsking for a T-shirt size

A shop asks for your T-shirt size: S, M or L. It doesn't need your exact measurements to pick a shirt. And a size tells a stranger far less about you than a tape measure would.

In real life: S, M, L or XL
In JavaScript: deviceMemory: 1, 2, 4, 8 ...
In real life: Your exact measurements
In JavaScript: The memory the device really has
In real life: A shirt that fits
In JavaScript: A page that suits the phone

The first number is navigator.deviceMemory: the device's memory in gigabytes (GB), as a size. The Device Memory spec says how to round it, and Chrome follows it (approximated_device_memory.cc):

How Chrome rounds the memoryPop out in the code editor (opens in a new tab)JavaScript
function deviceMemory(mb, android) {  const lower = 2 ** Math.floor(Math.log2(mb));  const upper = lower * 2;  const gb = (mb - lower <= upper - mb ? lower : upper) / 1024;  const [min, max] = android ? [1, 8] : [2, 32];  return Math.min(Math.max(gb, min), max);} console.log(deviceMemory(3072, true));   // a 3 GB Android phoneconsole.log(deviceMemory(16384, false)); // Ravi's 16 GB laptopconsole.log(deviceMemory(512, false));   // Chrome's low-end mode
  • Lines 2 and 3 find the two powers of two around the memory, in megabytes (MB). For 3,072 MB, they're 2,048 and 4,096.
  • Line 4 takes the nearer one. On a tie, it takes the lower one. Then it turns MB into GB.
  • Line 5 sets the limits: 1 to 8 on Android, and 2 to 32 on a computer. Line 6 keeps the answer inside them.
  • Lines 9 to 11 print 2, 16 and 2.

So a 3 GB phone says 2, and Chrome's low-end mode, at 512 MB, says 2 as well: a computer never goes below 2. The recording agreed. The page read 2 in low-end mode, and 16 in plain Chrome.

The second number is navigator.hardwareConcurrency. The HTML standard calls it "the number of logical processors potentially available". That's how many threads the CPU can run at once. DevTools can change it: its Sensors panel has a Hardware concurrency box (SensorsView.ts, lines 1076 to 1085). The course set it to 2. The page read 8 before, and 2 after.

Two warnings. First, the count says nothing about how fast each core is. Second, as lesson 37.1 found, DevTools' CPU slowdown changes neither number. Try a few memory sizes:

Playground: what deviceMemory says
Chromium's rounding, as a functionJavaScript
function deviceMemory(mb, android) {
  const lower = 2 ** Math.floor(Math.log2(mb));
  const upper = lower * 2;
  const gb = (mb - lower <= upper - mb ? lower : upper) / 1024;
  const [min, max] = android ? [1, 8] : [2, 32];
  return Math.min(Math.max(gb, min), max);
}
deviceMemory for 3 GB
  1. On an Android phone2
  2. On a computer2
This browser, right now
  1. This browserreading…
Try it yourself
3 GB: 2 on Android, 2 on a computer

Chrome takes the nearest power of two, rounding down on a tie. Then it keeps the answer between 1 and 8 on Android, and between 2 and 32 elsewhere.

The left pane is Chromium's rule, written as JavaScript. The lower list is read live from this browser. Firefox and Safari don't report deviceMemory.

Why it matters: memory doesn't change during a visit, so it's a steady signal. Ravi treats 2 GB or less as a phone that should get the lighter page.

Client hints: telling the server first

The page can read the memory. But by then, the big photo is already on its way. Ravi wants the server to know first. That's what client hints are for. They're request headers that describe the device. The browser sends them only after the server asks. Lesson 18.4 used them for image widths.

Real-life analogyAsking about allergies

On your first visit to a café, the bread comes before anyone asks about allergies. Then the waiter writes "ask about nuts" on your card for next time. A careful café asks at the door, before anything leaves the kitchen.

In real life: The waiter's note: "ask about nuts"
In JavaScript: Accept-CH: send these hints next time
In real life: Bread before anyone asks
In JavaScript: The first answer, chosen without hints
In real life: Asking at the door, then starting again
In JavaScript: Critical-CH: Chrome asks again, with the hints
In real life: The kitchen's two plates
In JavaScript: Vary: caches keep each version apart

The server asks with a response header. Here is the start of Ravi's answer:

Ravi's answer asks for four hintsHTTP
HTTP/1.1 200 OKContent-Type: text/html; charset=utf-8Accept-CH: Sec-CH-Device-Memory, ECT, RTT, DownlinkVary: Save-Data, Sec-CH-Device-Memory, ECT
  • Lines 1 and 2 start an ordinary answer: an HTML page.
  • Line 3, Accept-CH, asks for four hints on the next requests. Sec-CH-Device-Memory is the memory, as above. ECT, RTT and Downlink are the network values.
  • Line 4 lists every header that changes the answer.

Ravi's whole rule now reads all three signals:

function lighterPage(headers) {  if (headers["save-data"] === "on") return true;  if (Number(headers["sec-ch-device-memory"]) <= 2) return true;  return ["slow-2g", "2g"].includes(headers["ect"]);} console.log(lighterPage({}));console.log(lighterPage({ "sec-ch-device-memory": "2", ect: "4g" }));
  • Line 2 is Save-Data, from the last section.
  • Line 3 is the memory. Number() turns the header's text into a number. A missing header becomes NaN, and NaN <= 2 is false.
  • Line 4 is the network: a 2G connection, or a slower one.
  • Lines 7 and 8 try the 2 GB phone's two visits. They print false, then true.

Why two visits? On the first one, the request carried no hints. The server hadn't asked yet. So it sent the full page, with its 101 KB photo. The second request said Sec-CH-Device-Memory: 2, and the server sent the lighter page. Its photo was on screen at 1,256 ms, not 1,764 ms.

Critical-CH: the hint, on the first visit

To fix the first visit, Ravi adds one more line:

The answer names its critical hintHTTP
HTTP/1.1 200 OKContent-Type: text/html; charset=utf-8Accept-CH: Sec-CH-Device-Memory, ECT, RTT, DownlinkVary: Save-Data, Sec-CH-Device-Memory, ECTCritical-CH: Sec-CH-Device-Memory

Line 5, Critical-CH, tells Chrome that this hint changes the page a lot. If the request didn't carry it, Chrome throws the answer away and asks again, with the hint (critical_client_hints_throttle.cc, lines 78 to 187). It only does this once. And only for hints that Accept-CH also lists. Here is the 2 GB phone's first visit:

The 2 GB phone's first visit, with Critical-CH, in ms after the visit started. At 3 ms, Chrome asks for the page with no hint. Ravi's server sends the full page with Critical-CH: Sec-CH-Device-Memory. Chrome drops it and asks again at 581 ms, with Sec-CH-Device-Memory: 2. The server sends the lighter page, whose first byte arrives at 1,141 ms.2 GB phoneRavi's serverGET / (no hint)3 msfull page + Critical-CHGET / Sec-CH-Device-Memory: 2581 mslighter page1,141 msdropped
Times are in ms after the visit started. Chrome threw the first answer away and asked again with the hint. The lighter page arrived, but its first byte came at 1,141 ms: one more trip to the server.

The phone got the lighter page on its first visit. But it paid for it. The page's first byte came at 1,141 ms, not 563 ms. Its photo was on screen at 1,828 ms: later than the full page's 1,764 ms, even with a photo ten times smaller.

Why it matters: Critical-CH buys the right page on the first visit, for one more trip to the server. On a slow network, that trip is long. Use it only for a hint that changes the page a lot.

Where the ECT header comes from

Can DevTools' 3G preset test the network part of Ravi's rule? The course loaded the page twice under it:

Two hints on three requestsPop out in the code editor (opens in a new tab)JavaScript
// DevTools' 3G preset, second visit. Two hints on three requests.const requests = [  { file: "the page", ect: "4g", rtt: "50" },  { file: "page.js", ect: "2g", rtt: "1900" },  { file: "photo-1600.jpg", ect: "2g", rtt: "1900" },];for (const { file, ect, rtt } of requests) {  console.log(`${file}: ECT ${ect}, RTT ${rtt}`);}
  • Line 3 is the request for the page. Lines 4 and 5 are requests the page made.
  • It prints the page: ECT 4g, RTT 50, then page.js: ECT 2g, RTT 1900 and photo-1600.jpg: ECT 2g, RTT 1900.

Two different answers, on the same visit. Chrome builds the hints for the page itself from its own estimate of the real connection (client_hints.cc, lines 387 to 457). DevTools doesn't touch that estimate. The page's own requests take the values the page reads, and those include DevTools' preset (frame_fetch_context.cc, lines 687 to 730). On Ravi's laptop, the estimate said 4g.

Why it matters: to test a server rule on ECT, send the header yourself. And keep Vary right. The HTTP Client Hints standard, RFC 8942, says a server "MUST" send Vary when a hint changes an answer that can be cached. A request to another site, such as an image CDN, carries hints only if the page passes them on with Permissions-Policy, as in lesson 18.4.

Pick a visit to see what the server got, and what the page read:

Playground: what the server got, and what the page read
First visit
  1. The request for the pageno hints → full page
  2. Later requests said Save-Data: onno
  3. The page readsaveData false, effectiveType "3g", deviceMemory 16
  4. The extrasadded: font, video, reviews
  5. Downloaded before any tap339 KB
  6. First byte of the page563 ms
  7. Photo on screen (LCP)1,760 ms
  8. Add to cart (INP), the middle of three taps45 ms
Second visit, in the same tab
  1. The request for the pageSec-CH-Device-Memory 16, ECT 4g → full page
  2. Later requests said Save-Data: onno
  3. The page readsaveData false, effectiveType "3g", deviceMemory 16
  4. The extrasadded: font, video, reviews
  5. Downloaded before any tap339 KB
  6. First byte of the page563 ms
  7. Photo on screen (LCP)1,756 ms
Try it yourself
Ravi's laptop

No signal says Ravi needs less, so both visits get everything. On the second visit, the hints Accept-CH asked for come back.

From the course's recording in Chrome 157: the middle of 3 visits, on DevTools' Slow 4G preset with the CPU 4 times slower.

A lighter page that still works

Now the most important part. What goes into the lighter page? A page that loads fast but can't take Asha's order has failed. Addy Osmani described the pattern in two lines. Adaptive loading "delivers a fast core experience to all users". Then it "progressively adds high-end-only features" when the device and network can take them.

Real-life analogyPacking for a hike

Two friends climb the same hill. The strong one packs a camera and a big flask. The tired one packs water, a map and a snack. Both reach the top. There, the tired one can still borrow the camera for a photo.

In real life: Water, a map and a snack
In JavaScript: The price, the photo and Add to cart
In real life: A camera and a big flask
In JavaScript: The video and the web font
In real life: Borrowing the camera at the top
In JavaScript: A button that loads the video when asked
In real life: Both reach the top
In JavaScript: Both visitors can place the order

Ravi sorted every part of his page into four groups:

  • Keep it for everyone: the price and Add to cart. Every visit in the recording ended with Cart: 1.
  • Send a smaller one: the photo, 800 px wide instead of 1,600, as in lesson 18.2. That's 10 KB instead of 101 KB.
  • Wait for a tap: the video and the reviews become buttons, like the facades of lesson 19.2. The video's button says how big it is, so Asha can choose.
  • Leave it out: the handwriting font. The phone's own font reads just as well, as lesson 20.4 showed.

Read the table across. Each row is one part of the page, on both versions:

The same page, two ways
Part of the pageFull pageLighter page
The price and Add to cartShown at once.Shown at once. Nothing changes.
The tea photo1,600 px wide.800 px wide: plenty for a phone's screen.
The heading fontCaveat, a web font.The phone's own font.
The brewing videoPlays by itself.A button that says how big it is.
The 50 reviewsFetched and shown at once.A button. One tap fetches them.

Here is what each part downloaded, to scale:

What each part of the page downloaded, to scale. tea photo: full page 101 KB; lighter page 10 KB. brewing video: full page 154 KB; lighter page 154 KB, only after a tap. heading font: full page 74 KB; lighter page nothing. reviews: full page 6 KB; lighter page 6 KB, only after a tap. page and script: full page 5 KB; lighter page 5 KB.top bar: full page · lower bar: lighter pagetea photo101 KB10 KBbrewing video154 KB154 KB, after a tapheading font74 KBnone: the phone's own fontreviews6 KB6 KB, after a tappage and script5 KB5 KB
Each pair of bars is one part of the page: the full page on top (shaded), the lighter page below. The lighter page fetches the video and the reviews only if Asha taps for them.

Did the buttons work? Yes. On the lighter page, the reviews were in the page 665 ms after Asha's tap. The video was playing 879 ms after she tapped its button. Each tap waits for one trip to the server. So each button says "Loading…" straight away.

The page checks too

The server can't catch every case. On a first visit, it has only Save-Data. So the page's script checks the signals again before it adds any extras:

page.js decides before it adds the extrasJavaScript
// At the top of page.js, on both pages.const connection = navigator.connection;const wantsLess =  document.documentElement.dataset.light === "yes" ||  connection?.saveData === true ||  ["slow-2g", "2g"].includes(connection?.effectiveType) ||  navigator.deviceMemory <= 2;
  • Line 1 is a comment. Line 2 keeps the connection, if the browser has one.
  • Line 3 starts wantsLess. It's true if any of the next four tests passes.
  • Line 4 is the server's choice: the lighter page has data-light="yes" on its <html>.
  • Lines 5 and 6 are Save-Data and a 2G connection. The ?. gives undefined when there's no connection, instead of an error.
  • Line 7 is the memory.

If wantsLess is true, the page offers the buttons. Otherwise it adds the font, the video and the reviews. This caught the 2 GB phone's first visit: the big photo still came, but the page stopped at 106 KB, not 339 KB. It caught DevTools' menu too, at 106 KB.

One choice is left. In a browser with none of these values, every test is false, so the page adds everything. The Device Memory spec asks you to make that choice on purpose. Ravi chose the full page, so those visitors get what they always got.

Ravi wrote these checks by hand: they're a few lines. For React apps, Google Chrome Labs published react-adaptive-hooks. It reads the same signals as hooks.

Why it matters: a lighter page sends fewer bytes, not fewer features. Keep what visitors came for. Make everything else smaller, or let them ask for it.

Keep it, shrink it, or wait?

Sort each part of a shop page by what the lighter page should do with it:

Keep it, shrink it, or wait?
  • The Add to cart button
  • The price and the brewing steps
  • The 1,600 px tea photo
  • Four more product photos
  • The brewing video that plays by itself
  • The 50 reviews
  • A chat widget's script
  • The handwriting font for the headings
Try it yourself
0 of 8 correct

Sort each part by what the lighter page does with it.

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

Common mix-ups

  • "The server learns the device's memory on the first visit." No. Only after Accept-CH asks for it, or after a Critical-CH retry. Save-Data is the one that comes at once.
  • "effectiveType is the kind of network, like 4G." No. It's a guess from recent round trips. DevTools' Slow 4G reads as 3g.
  • "DevTools' presets change every header the server sees." No. The request for the page carries Chrome's own estimate. Only the page's later requests carry the preset.
  • "deviceMemory is the exact memory." No. It's rounded to a power of two, and kept between 1 and 8 on Android, or 2 and 32 on a computer.
  • "No navigator.connection means a slow device." No. Firefox and Safari don't have it at all. Choose your default on purpose.
  • "A lighter page means fewer features." No. Asha could still add to cart, read every review and watch the video. She chose when.

Practice exercises

Answer first, then use the hints.

Exercise 1 · Warm-upA 4 GB phone on 3g

A phone with 4 GB, on a 3g connection, visits Ravi's page. What does it print?

Starter codePop out in the code editor (opens in a new tab)JavaScript
function lighterPage(headers) {
  if (headers["save-data"] === "on") return true;
  if (Number(headers["sec-ch-device-memory"]) <= 2) return true;
  return ["slow-2g", "2g"].includes(headers["ect"]);
}

console.log(lighterPage({ "sec-ch-device-memory": "4", ect: "3g" }) ? "lighter page" : "full page");

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

    Exercise 2 · Warm-upA 6 GB phone

    Asha's cousin has a 6 GB Android phone. What does it print?

    Starter codePop out in the code editor (opens in a new tab)JavaScript
    function deviceMemory(mb, android) {
      const lower = 2 ** Math.floor(Math.log2(mb));
      const upper = lower * 2;
      const gb = (mb - lower <= upper - mb ? lower : upper) / 1024;
      const [min, max] = android ? [1, 8] : [2, 32];
      return Math.min(Math.max(gb, min), max);
    }
    
    console.log(deviceMemory(6144, true));

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

      Exercise 3 · PracticeA 1,500 ms round trip

      Chrome sees round trips of about 1,500 ms. What does it print?

      Starter codePop out in the code editor (opens in a new tab)JavaScript
      function effectiveType(rttMs) {
        if (rttMs >= 2010) return "slow-2g";
        if (rttMs >= 1420) return "2g";
        if (rttMs >= 272) return "3g";
        return "4g";
      }
      
      console.log(effectiveType(1500));

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

        Exercise 4 · PracticeWho asked for the font?

        Open Ravi's full page in Chrome, with DevTools' Network panel open, and reload. Which file is the Initiator of the request for caveat.woff2?

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

          Exercise 5 · ChallengeThe wrong page from the CDN

          Ravi's laptop sometimes gets the lighter page from his CDN. Which response header did the server forget?

          Starter codePop out in the code editor (opens in a new tab)JavaScript
          // Ravi's server, behind a CDN that keeps each page for a minute.
          const lighter = lighterPage(request.headers);
          response.setHeader("Cache-Control", "public, max-age=60");
          response.setHeader("Accept-CH", "Sec-CH-Device-Memory, ECT, RTT, Downlink");
          response.end(lighter ? lightHtml : fullHtml);

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

            Exercise 6 · ChallengeThe photo on DevTools' 3G

            In the playground of recorded visits, pick DevTools' 3G. When was the photo on screen on the first visit, in ms?

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

              Check your understanding

              For each question, ask yourself who reads the signal: the server, or the page.

              The adaptive loading quiz · 7 questionsScore: first tries count
              1. Question 1 of 7Asha opens Ravi's page for the first time, with Data Saver on. Which of these is on the very first request for the page?

                Choose an answer to see the explanation.

              2. Question 2 of 7Ravi's answer says Critical-CH: Sec-CH-Device-Memory, and the first request didn't carry that hint. What does Chrome do?

                Choose an answer to see the explanation.

              3. Question 3 of 7DevTools is set to its Slow 4G preset. What does navigator.connection.effectiveType say?

                Choose an answer to see the explanation.

              4. Question 4 of 7What does this check print in a browser that has neither API?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                // page.js's check, in a browser without navigator.connection or deviceMemory.
                const navigator = {};
                const document = { documentElement: { dataset: {} } };
                const connection = navigator.connection;
                const wantsLess =
                  document.documentElement.dataset.light === "yes" ||
                  connection?.saveData === true ||
                  ["slow-2g", "2g"].includes(connection?.effectiveType) ||
                  navigator.deviceMemory <= 2;
                console.log(wantsLess);

                Choose an answer to see the explanation.

              5. Question 5 of 7Why does Ravi's server send Vary: Save-Data, Sec-CH-Device-Memory, ECT with the page?

                Choose an answer to see the explanation.

              6. Question 6 of 7Ravi's friend has a laptop with 64 GB of memory. What does navigator.deviceMemory say in Chrome?

                Choose an answer to see the explanation.

              7. Question 7 of 7Which change makes a lighter page stop working?

                Choose an answer to see the explanation.

              Key takeaways

              • Save-Data comes on every request while it's on, the first one too. Use it to send the lighter page.
              • effectiveType is a word Chrome picks from recent round trips. rtt and downlink are rounded and blurred.
              • deviceMemory is rounded to a power of two. hardwareConcurrency counts cores, not their speed.
              • Client hints reach the server after Accept-CH asks. Critical-CH gets them on the first visit, for one more trip.
              • Send Vary with every hint that changes the page, so caches keep the versions apart.
              • A lighter page keeps what visitors came for, sends smaller files, and turns heavy extras into a tap.

              Remember the one-liner.
              Read what the browser tells you, and send a lighter page that still does everything the visitor came for.

              Sources

              The facts on this page come from these specs, posts and source files:

              Coming next: Slow and unreliable networks. What happens when the network drops out halfway, and how to keep a page usable anyway.

              CompleteFrontend Clear concepts. Working examples.