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.
- 01Read 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.
- 02Let 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.
- 03Build 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:
Under each frame is the data that had arrived. Here are the numbers that matter most:
// 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.
kbis how much it downloaded.photoAtis when the tea photo was on screen: the page's largest contentful paint, or LCP, from lesson 17.1. cartis 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 msandLighter 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.
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
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: onto every request, and setsaveDatato 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:
// 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-Dataheader. Node gives header names in lower case. - Line 3 adds
Vary: Save-Data. Lesson 15.1 metVary. 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:
// 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: onandphoto-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.
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:
rttanddownlink, 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:
// 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):
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 prints2gfor 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:
// 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 msandFast 4G: 4g, rtt 200, 150, 150 ms. ThenSlow 4G: 3g, rtt 600, 600, 550 msand3G: 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:
function effectiveType(rttMs) {
if (rttMs >= 2010) return "slow-2g";
if (rttMs >= 1420) return "2g";
if (rttMs >= 272) return "3g";
return "4g";
}- effectiveType"3g"
- Line it passed272 ms
- What rtt can read500 ms to 600 ms
- This browserreading…
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.
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.
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):
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,16and2.
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:
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);
}- On an Android phone2
- On a computer2
- This browserreading…
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.
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.
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:
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-Memoryis the memory, as above.ECT,RTTandDownlinkare 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 becomesNaN, andNaN <= 2is 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, thentrue.
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:
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-MemoryLine 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 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:
// 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, thenpage.js: ECT 2g, RTT 1900andphoto-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:
- The request for the pageno hints → full page
- Later requests said Save-Data: onno
- The page readsaveData false, effectiveType "3g", deviceMemory 16
- The extrasadded: font, video, reviews
- Downloaded before any tap339 KB
- First byte of the page563 ms
- Photo on screen (LCP)1,760 ms
- Add to cart (INP), the middle of three taps45 ms
- The request for the pageSec-CH-Device-Memory 16, ECT 4g → full page
- Later requests said Save-Data: onno
- The page readsaveData false, effectiveType "3g", deviceMemory 16
- The extrasadded: font, video, reviews
- Downloaded before any tap339 KB
- First byte of the page563 ms
- Photo on screen (LCP)1,756 ms
No signal says Ravi needs less, so both visits get everything. On the second visit, the hints Accept-CH asked for come back.
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.
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:
| Part of the page | Full page | Lighter page |
|---|---|---|
| The price and Add to cart | Shown at once. | Shown at once. Nothing changes. |
| The tea photo | 1,600 px wide. | 800 px wide: plenty for a phone's screen. |
| The heading font | Caveat, a web font. | The phone's own font. |
| The brewing video | Plays by itself. | A button that says how big it is. |
| The 50 reviews | Fetched and shown at once. | A button. One tap fetches them. |
Here is what each part downloaded, to scale:
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:
// 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
?.givesundefinedwhen 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:
- 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
Sort each part by what the lighter page does with it.
Common mix-ups
- "The server learns the device's memory on the first visit." No. Only after
Accept-CHasks for it, or after aCritical-CHretry. 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.
A phone with 4 GB, on a 3g connection, visits Ravi's page. What does it print?
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");full page. No line of the rule matches, so the function returns false.
Asha's cousin has a 6 GB Android phone. What does it print?
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));4. 6,144 MB sits halfway between 4,096 and 8,192, and a tie goes down. 4 is inside Android's limits.
Chrome sees round trips of about 1,500 ms. What does it print?
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));2g. 1,500 ms passes the 1,420 ms line, but not the 2,010 ms one.
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?
fonts.css. page.js adds fonts.css, and the @font-face rule in fonts.css asks for the font. So the font starts only after both have arrived.
Ravi's laptop sometimes gets the lighter page from his CDN. Which response header did the server forget?
// 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);response.setHeader("Vary", "Save-Data, Sec-CH-Device-Memory, ECT");Vary. Without it, the CDN keeps one copy. Asha's lighter page can reach Ravi's laptop, or the full page can reach Asha.
In the playground of recorded visits, pick DevTools' 3G. When was the photo on screen on the first visit, in ms?
6,220 ms. The page read 2g and offered the buttons, but the server didn't know: it sent the 1,600 px photo. On 3G, each request also waits 2 seconds for its answer.
Check your understanding
For each question, ask yourself who reads the signal: the server, or the page.
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.
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.
Question 3 of 7DevTools is set to its Slow 4G preset. What does
navigator.connection.effectiveTypesay?Choose an answer to see the explanation.
Question 4 of 7What does this check print in a browser that has neither API?
Read the code, then predict// 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.
Question 5 of 7Why does Ravi's server send
Vary: Save-Data, Sec-CH-Device-Memory, ECTwith the page?Choose an answer to see the explanation.
Question 6 of 7Ravi's friend has a laptop with 64 GB of memory. What does
navigator.deviceMemorysay in Chrome?Choose an answer to see the explanation.
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.
effectiveTypeis a word Chrome picks from recent round trips.rttanddownlinkare rounded and blurred.deviceMemoryis rounded to a power of two.hardwareConcurrencycounts cores, not their speed.- Client hints reach the server after
Accept-CHasks.Critical-CHgets them on the first visit, for one more trip. - Send
Varywith 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:
- Save Data API, WICG.
- client_hints.cc: hints sent without asking, Chromium source.
- client_hints.cc: Save-Data and network hints on the page's own request, Chromium source.
- frame_fetch_context.cc: hints on the page's later requests, Chromium source.
- ThrottlingManager.ts: DevTools' Save-Data menu, Chrome DevTools source.
- Network Information API, WICG.
- network_quality_estimator_params.h: the round-trip lines, Chromium source.
- network_state_notifier.cc: DevTools' presets, rounding and noise, Chromium source.
- inspector_network_agent.cc: DevTools' network override, Chromium source.
- NetworkManager.ts: DevTools' network presets, Chrome DevTools source.
- Device Memory, W3C.
- approximated_device_memory.cc, Chromium source.
- HTML Standard: navigator.hardwareConcurrency, WHATWG.
- SensorsView.ts: DevTools' Hardware concurrency box, Chrome DevTools source.
- RFC 8942: HTTP Client Hints, IETF.
- Client Hint Reliability (Critical-CH), IETF draft.
- client_hints.cc: the hints' header names, Chromium source.
- critical_client_hints_throttle.cc, Chromium source.
- Adaptive Loading: improving web performance on low-end devices, Addy Osmani.
- react-adaptive-hooks, Google Chrome Labs.
Coming next: Slow and unreliable networks. What happens when the network drops out halfway, and how to keep a page usable anyway.