Rendering strategies compared
Measure one page built five ways, from client rendering to islands, and see how TTFB, LCP, INP and the moment a button works move with each.
- 01Measure the same page five waysCompare client rendering, server rendering, static, revalidated and islands builds by TTFB, LCP, taps and JavaScript.
- 02Say where each build puts the waitTell which metric pays for building the page in the browser, on the server for each visit, or ahead of time.
- 03Pick a build for each pageChoose from what a page needs: the same for everyone or personal, fresh or a little old, still or interactive.
One page, five ways to build it
Welcome to Stage 11, Architecture and frameworks. So far, you've made one thing faster at a time: a font, a photo, a script. This stage steps back. Long before you tune anything, the way a site is built has decided much of its speed. Where is the HTML made? When is it made? How much JavaScript must run before a button works? Every framework answers these questions in its own way. This first lesson measures the answers on one page.
Ravi wants to rebuild his shop, Leaf and Kettle. In lesson 34.1, he made it a single-page app. Now everyone has advice. A friend says server rendering is faster. A blog says static pages are best. Someone else talks about islands. And Ravi has just raised the price of 100 g of Mint tea, from £4.50 to £4.80.
Which build is fastest for his Mint tea page? And which builds show the new price? Ravi builds the same page five ways. Each one makes the page's HTML in a different place, or at a different time:
- Client rendering: the server sends an almost empty page. JavaScript in Asha's browser fetches the tea's data and draws the page.
- Server rendering: Ravi's server builds the whole page for every visit.
- Static: the page was built once, ahead of time. The server keeps it and sends it at once.
- Static with revalidation: the same, but the kept page is rebuilt now and then, in the background.
- Islands: a static page where only one part, the buy box, gets JavaScript.
Asha opens each one. Here are the five, side by side, at the same four moments:
Look at the first row. At 300 ms, three builds already show the name and the size picker. The server build shows nothing at all. The client build shows only the green header. By 1,100 ms, all five look the same. Here are two moments from each visit:
// Two moments of Asha's visit, in ms: the photo on screen (LCP), and the first moment 50 g worked.// The middle of 5 loads of each build.const builds = [ ["Client", 1052, 768.9], ["Server", 712, 604.8], ["Static", 460, 351.3], ["Revalidate", 464, 355.4], ["Islands", 460, 348.9],];for (const [build, photo, works] of builds) console.log(`${build}: photo ${photo} ms, picker ${works} ms`);- Lines 1 and 2 are comments. The course loaded each build 5 times, and these are the middle loads.
- Lines 4 to 8 hold each build: its name, when the photo was on screen, and the first moment a tap on 50 g worked. Times are in milliseconds (ms) after Asha opened the page.
- Line 10 prints one line per build. The first two are
Client: photo 1052 ms, picker 768.9 msandServer: photo 712 ms, picker 604.8 ms. - The other three are
Static: photo 460 ms, picker 351.3 ms,Revalidate: photo 464 ms, picker 355.4 msandIslands: photo 460 ms, picker 348.9 ms.
The photo is the page's largest contentful paint, or LCP: the biggest thing on the screen, as lesson 17.1 showed. The static builds put it on screen more than twice as fast as the client build. It was the same page, the same photo and the same network. Only the build changed. Why did that matter so much?
You need a cake for a party. A kit can come in the post, and you bake it yourself. The bakery can bake one while you wait at the counter. You can take one from this morning's shelf. When the shelf cake gets old, the baker can bake a fresh one for the next customer. Or you can buy a shelf cake with one candle that you light yourself.
- In real life: A kit you bake at home
- In JavaScript: Client rendering: the browser builds the page
- In real life: A cake baked while you wait at the counter
- In JavaScript: Server rendering: the page is built for each visit
- In real life: A cake from this morning's shelf
- In JavaScript: Static: built ahead, sent at once
- In real life: A fresh cake baked for the next customer
- In JavaScript: Revalidation: rebuilt in the background
- In real life: A shelf cake with one candle you light
- In JavaScript: Islands: only one part needs JavaScript
A rendering strategy decides where and when a page's HTML is built. That moves the wait. Building on the server for each visit delays the first byte. Building in the browser delays the content. Code that wakes the page up delays the first tap that works.
For the basics of each strategy, with React code, see Rendering strategies. For choosing one in a big app, see Choosing a rendering strategy. Here, you measure them.
How the course recorded it
- Ravi's page: his Mint tea page, as in Module 34, now with a buy box and 24 reviews. The buy box holds the size picker (50 g or 100 g), the price, and Add to cart.
- Five builds, written by hand: plain JavaScript and no framework, so you can read every line. A framework adds its own code to each build. Lesson 23.3 measured React's.
- Asha's network: the course's own server played Fast 4G, as in Module 34. Each answer waited 165 ms. Building the page, or its data, took Ravi's server 250 ms more.
- Asha's computer: Chrome 157, in a window 500 pixels wide, with the CPU 4 times slower.
- The loads: each build 5 times while Asha only watched, and 5 times while she tapped. The builds took turns.
- The taps: mouse clicks, which DevTools passes straight to the page. Asha tapped 50 g every 50 ms, from the moment Chrome had drawn it, until the price changed.
Move through Asha's visits yourself. Each frame is real:
- Client
only the green headerpicker: no picker - Servera blank pagepicker: no picker
- Static
the words and the picker, no photo yetpicker: not working - Revalidate
the words and the picker, no photo yetpicker: not working - Islands
the words and the picker, no photo yetpicker: not working
Move the slider. Each frame is the last one Chrome had drawn by then, in the middle load of each build. Under it: what a tap on 50 g did at that moment.
Client rendering: an empty page, then a chain of trips
Start with the build from lesson 34.1. With client rendering, the server sends a page with almost nothing in it. The browser builds the rest. Here is the client build's whole body:
<body> <header><span>Leaf and Kettle</span></header> <main id="app"></main> <script type="module" src="app.js"></script></body>- Line 2 is the green header. At first, that's all Asha can see.
- Line 3 is
main, and it's empty. The page will go here. - Line 4 loads app.js. It's a module script: it waits until the HTML has been read, then runs.
Here is the part of app.js that runs:
const app = document.querySelector("#app");const tea = await fetch("data/mint-tea.json").then((response) => response.json());app.innerHTML = teaPage(tea);listen(app.querySelector(".buy"), tea.prices);performance.mark("picker-works");- Line 1 finds the empty
main. - Line 2 asks Ravi's server for the tea's data, data/mint-tea.json.
awaitwaits here until it has arrived. - Line 3 builds the whole page's HTML with
teaPage, a function that returns HTML text. Then it puts the HTML inmain. - Line 4 makes the buy box work.
listenadds a click handler to it. - Line 5 writes down the time, named
picker-works, withperformance.mark(). That's how the course knows when the picker started to work.
Notice the order. The browser can't know about the photo until line 3 has run. And line 3 waits for line 2. Here are the four files Asha's browser fetched:
// The client build's four trips, in ms after Asha opened the page.const trips = [ ["mint-tea.html", 0.8, 167.1], ["app.js", 176, 347.3], ["mint-tea.json", 349.2, 765.8], ["mint-tea.jpg", 770.4, 1037.3],];for (const [file, asked, arrived] of trips) console.log(`${file}: asked at ${asked} ms, arrived at ${arrived} ms`);- Lines 2 to 7 hold each file: when Chrome asked for it, and when its last byte arrived.
- Line 8 prints
mint-tea.html: asked at 0.8 ms, arrived at 167.1 ms, thenapp.js: asked at 176 ms, arrived at 347.3 ms. - Then
mint-tea.json: asked at 349.2 ms, arrived at 765.8 msandmint-tea.jpg: asked at 770.4 ms, arrived at 1037.3 ms.
Each file was asked for only after the one before it arrived. The HTML named app.js. app.js asked for the data. Only the data named the photo. The data took longest: the 165 ms trip, plus 250 ms while Ravi's server built it.
In a treasure hunt, the first clue says where the second one is hidden. You can't look for the third clue until you've read the second. Every clue may be close by. But the walks still add up, one after another.
- In real life: Each clue
- In JavaScript: Each file: the HTML, app.js, the data, the photo
- In real life: A clue that says where the next one is
- In JavaScript: A file that names the next file to fetch
- In real life: The walks adding up
- In JavaScript: The trips' waits adding up
- In real life: The treasure
- In JavaScript: The photo on screen: the LCP
Why it matters: every trip adds a wait. A chain of four trips put the photo on screen at 1,052 ms, last of the five builds.
The client build got one thing right. app.js drew the picker and made it work in the same task. The picker worked at 768.9 ms, just before Chrome painted it. So Asha never saw a picker that ignored her.
Client rendering also keeps Ravi's server simple: it only sends files. But the page waits for its code and its data. And web.dev warns that the code "tends to grow as an application grows, which can impact a page's INP." INP measures how quickly a page answers taps, as lesson 26.1 showed.
Server rendering: a whole page, after the server's wait
With server rendering, Ravi's server builds the whole HTML for each visit. The course's server did it like this:
// The course's server, for every visit to the server build's mint-tea.html.async function build(price) { await sleep(250); // stands in for reading Mint tea from Ravi's database return serverHtml(teaData(price));}- Line 2 starts
build, with the tea's price. - Line 3 waits 250 ms. It stands in for reading Mint tea from Ravi's database.
- Line 4 builds the page's HTML. Inside, it uses the same
teaPageas app.js, run on the server.
Nothing can leave the server until line 4 has run. It's like a café that cooks your whole order before it brings anything to the table.
// The server build, in ms after Asha opened the page: the middle of 5 loads.const firstByte = 418.7;const pickerDrawn = 485.8;const pickerWorks = 604.8; console.log(`First byte: ${firstByte} ms`);console.log(`Drawn, but not working: ${(pickerWorks - pickerDrawn).toFixed(1)} ms`);- Lines 2 to 4 hold three recorded times.
- Line 6 prints
First byte: 418.7 ms. That's the time to first byte, or TTFB, from lesson 14.1: the 165 ms trip, plus the server's 250 ms. - Line 7 prints
Drawn, but not working: 119.0 ms.
Once the first byte came, the page came whole. The photo's address was in the HTML, so Chrome asked for it at once. The photo was on screen at 712 ms, 340 ms before the client build's. web.dev says server rendering "generally produces a fast FCP", the first contentful paint. It also warns that building pages on the server "can increase your page's TTFB." Both showed up here.
Drawn, but not working yet
So why did the picker ignore Asha for 119 ms? HTML can't answer a tap by itself. Some code has to attach the click handler. That's hydration, from lesson 23.3: running the page's code again in the browser, over HTML that's already there. Here is the main part of page.js:
const app = document.querySelector("#app");const tea = JSON.parse(document.querySelector("#tea").textContent);hydrate(app, teaPage(tea));listen(app.querySelector(".buy"), tea.prices);performance.mark("picker-works");- Line 1 finds
main, which is full this time. - Line 2 reads the tea's data from the page. The server put a second copy of it in a script tag, with the id
tea. - Line 3 hydrates the whole page. Line 4 makes the buy box work. Line 5 marks the moment.
And here is hydration, written by hand:
function hydrate(element, html) { const again = element.cloneNode(false); again.innerHTML = html; if (!again.isEqualNode(element)) element.innerHTML = html;}- Line 2 makes an empty copy of the element. Line 3 builds its HTML again, inside the copy.
- Line 4 compares the copy with the page, using
isEqualNode(). Only if they differ does it replace the page's HTML.
They matched every time: the course's notes show no changes to main during hydration. But first, page.js had to arrive. Chrome asked for it just after the HTML, at 429.8 ms. It arrived at 600.6 ms, one more 165 ms trip later. Until it ran, 50 g was only HTML. Asha's first three taps did nothing at all. Pick a build to see each tap:
- 50 g drawn476.7 ms
- Tap 1, at 483.6 msdid nothing
- Tap 2, at 531 msdid nothing
- Tap 3, at 581.5 msdid nothing
- Tap 4, at 634 msworked; next paint in 16 ms
Pick a build. Each row is one of Asha's taps on 50 g, in the middle tap load. She tapped every 50 ms from the moment Chrome had drawn the button, until the price changed. Event Timing gives the time to the next paint; it reports nothing under 16 ms.
Why it matters: a page can look ready before it is. Here, the gap was one trip for a small script. With a framework, hydration also runs the framework's code, and lesson 23.3 measured a gap of almost a second.
One more cost hides in the HTML. The tea's data travelled twice: once as the page, and once in the script tag for page.js. web.dev calls this "One app for the price of two".
Static pages, and keeping them fresh
Ravi's server built the same HTML for every visitor. Why build it again each time? A static page is built once, ahead of time, and kept. Frameworks call this static generation, or prerendering. Every visit gets the kept copy at once.
// The first byte and the photo, in ms: the middle of 5 loads each.const server = { firstByte: 418.7, photo: 712 };const staticBuild = { firstByte: 167, photo: 460 }; console.log(`First byte: ${(server.firstByte - staticBuild.firstByte).toFixed(1)} ms sooner`);console.log(`Photo: ${server.photo - staticBuild.photo} ms sooner`);- Lines 2 and 3 hold the first byte and the photo of the server and static builds.
- Line 5 prints
First byte: 251.7 ms sooner. Line 6 printsPhoto: 252 ms sooner.
That's the 250 ms build, gone from every visit. Everything else was the same: the same HTML, the same page.js and the same trips. web.dev says static rendering gets "a consistently fast TTFB, because the HTML for a page doesn't have to be dynamically generated on the server." Why it matters: if a page is the same for everyone, building it once saves every visitor the wait.
Now look at the static build's price in the opening picture: £4.50. Ravi raised it to £4.80, and the static page never noticed. It was built before the change. The client and server builds read the database on every visit, so they showed £4.80. A static page is only as fresh as its last build.
In a shop, each tin has a printed price label. When the price changes, someone must print a new label. Until then, the old label stays on the shelf. A shopper who comes now sees the old price. The assistant prints the new label while she shops. The next shopper sees the new price.
- In real life: The printed label
- In JavaScript: The kept static page
- In real life: The new price in the till
- In JavaScript: The new price in Ravi's database
- In real life: Printing a new label while she shops
- In JavaScript: Rebuilding the page in the background
- In real life: The next shopper
- In JavaScript: The next visitor, who gets the fresh page
That's revalidation: keep the static page, but rebuild it once it gets too old. Here is Ravi's rule:
// Send the kept page at once. If it's over 60 s old, build a fresh one in the background.async function revalidatingPage() { if (Date.now() - kept.builtAt > 60_000) { kept.builtAt = Date.now(); build(database.price).then((html) => (kept.html = html)); } return kept.html;}- Line 3 checks how old the kept page is.
60_000ms is 60 seconds. - Line 4 notes the time now, so only one rebuild starts.
- Line 5 starts a build without
await, so the visit doesn't wait for it. When the build ends, its HTML becomes the kept page. - Line 7 sends the kept page, whatever its age.
Instead of waiting a minute before each visit, the course marked the kept page as too old, then let Asha in. Next.js does the same with one line:
// app/teas/[slug]/page.js in Next.js: keep the page, and rebuild it at most once a minute.
export const revalidate = 60;Line 2 tells Next.js to keep the page, and to rebuild it at most once every 60 seconds. Next.js's docs say a request after that "will still return the cached (now stale) page", while a new version "begins generating in the background". It's lesson 15.2's café newspaper, for whole pages. RFC 5861, which defines stale-while-revalidate, says it lets a cache "immediately return a stale response while it revalidates it in the background."
// Ravi has changed the 100 g price to £4.80. Asha, then Ben, open the revalidating build.const asha = { firstByte: 167.2, price: "£4.50" };const rebuild = { started: 0.1, ended: 250.8 }; // ms after Asha's request reached the serverconst ben = { firstByte: 167, price: "£4.80" }; console.log(`Asha: ${asha.price} for 100 g, first byte at ${asha.firstByte} ms`);console.log(`Ben: ${ben.price} for 100 g, first byte at ${ben.firstByte} ms`);- Line 2 holds Asha's visit: her first byte, and the price she saw.
- Line 3 holds the rebuild, on the server's clock.
- Line 4 holds Ben's visit, a few seconds later.
- Lines 6 and 7 print
Asha: £4.50 for 100 g, first byte at 167.2 msandBen: £4.80 for 100 g, first byte at 167 ms.
Both first bytes came as fast as the static page's. The rebuild ran for about 250 ms beside Asha's visit, and she never waited for it. Why it matters: revalidation keeps static speed, at the cost of one visit with old data. So use it where an old price for one visit does no harm.
Where an old price would be wrong, rebuild the page when the price changes. Next.js's revalidatePath marks a page as out of date. Its docs say the new page is then built on the next request. Step through the two visits:
- The kept page£4.50 for 100 g, over a minute old
- Ravi's database£4.80 for 100 g
Ravi has raised the 100 g price. The page his server keeps still has the old one, and it's older than the 60 seconds he allows.
Islands: code only for the part that moves
Look at the static page again. Almost all of it never moves: the photo, the name, the words and 24 reviews. Only the buy box answers taps. Yet page.js builds all of it again, just to attach one click handler.
Islands fix that. Jason Miller described the idea in 2020. Render the page as HTML on the server, and mark its "highly dynamic regions". Each region is hydrated on its own, "into small self-contained widgets". The rest stays plain HTML, with no code. He credits the name to Katie Sylor-Miller at Etsy.
Some birthday cards play a tune when you open them. The card itself is only paper. The picture and the words need no battery. Only a small chip in the fold has a battery and a speaker. Nobody puts a battery behind every word.
- In real life: The paper, the picture and the words
- In JavaScript: The static HTML: photo, name and reviews
- In real life: The sound chip
- In JavaScript: The island: the buy box
- In real life: The chip's small battery
- In JavaScript: buy-box.js, the island's own code
- In real life: No battery behind the words
- In JavaScript: No JavaScript for the parts that never move
Here is the islands build's buy box, and its only script:
<div class="buy" data-prices='{"50":"£2.50","100":"£4.50"}'> <!-- the buy box's HTML, as it was built --></div><script type="module" src="buy-box.js"></script>- Line 1 is the buy box. Its prices travel with it, in a
data-pricesattribute. - Line 2 stands for the buy box's HTML, the same as on the static page.
- Line 4 loads the page's only script, buy-box.js.
const buy = document.querySelector(".buy");const prices = JSON.parse(buy.dataset.prices);hydrate(buy, buyBox(prices, 100));listen(buy, prices);performance.mark("picker-works");- Line 1 finds the buy box. Line 2 reads its prices from the attribute.
- Line 3 hydrates only the buy box, with the same
hydrateas page.js. - Lines 4 and 5 make it work, and mark the moment.
Compare it with page.js. There's no teaPage, no reviews, and no second copy of the tea's data.
Astro is a framework built around islands. Its pages stay plain HTML unless you mark a part:
<!-- In an Astro page: only BuyBox gets JavaScript, loaded at once. -->
<BuyBox client:load prices={tea.prices} />Line 2 marks BuyBox with client:load. Astro's docs say this loads and hydrates its code "immediately on page load". A part with no client:* directive is "not hydrated in the client". Other directives wait: client:idle until the browser is idle, and client:visible until the part scrolls into view.
// Static and islands, the middle of 5 loads each. Sizes are the gzipped bytes that travelled.const staticBuild = { script: 760, html: 2164, works: 351.3 };const islands = { script: 549, html: 1904, works: 348.9 }; console.log(`Less JavaScript: ${staticBuild.script - islands.script} bytes`);console.log(`Less HTML: ${staticBuild.html - islands.html} bytes`);console.log(`Picker works sooner by: ${(staticBuild.works - islands.works).toFixed(1)} ms`);- Lines 2 and 3 hold each build's script size, its HTML size, and when its picker worked.
- It prints
Less JavaScript: 211 bytes,Less HTML: 260 bytesandPicker works sooner by: 2.4 ms.
2.4 ms is nothing. Both builds waited for the same thing: one more 165 ms trip for a small script. And the code that islands skip was tiny on this page. All the JavaScript on the static page ran in under 10 ms, even on Asha's slow CPU.
Why it matters: islands save the code that the still parts would run. So they help as much as that code weighs. With a framework, every part carries its share. In lesson 23.3, React's islands page needed 60.3 KB of JavaScript before Asha scrolled, against 74.1 KB to hydrate everything. A later lesson in this module compares more ways to hydrate.
Five builds, side by side
Here are all five builds, drawn to scale:
And here are their numbers. Read each row across:
| Build | First byte (TTFB) | Photo on screen (LCP) | Picker works from | Taps that did nothing | JavaScript sent |
|---|---|---|---|---|---|
| Client rendering | 165.9 ms | 1,052 ms | 768.9 ms | 0 | 715 bytes |
| Server rendering | 418.7 ms | 712 ms | 604.8 ms | 3 | 760 bytes |
| Static | 167 ms | 460 ms | 351.3 ms | 3 | 760 bytes |
| Static with revalidation | 166.8 ms | 464 ms | 355.4 ms | 3 | 760 bytes |
| Islands | 166 ms | 460 ms | 348.9 ms | 3 | 549 bytes |
Each column answers one question:
- TTFB: four builds had their first byte at about 166 ms, the trip alone. Server rendering's came at 418.7 ms. Why it matters: TTFB pays for whatever the server does before it sends.
- LCP: the three static builds put the photo on screen first, at 460 to 464 ms. Server rendering came next, then client rendering. Why it matters: LCP pays for every trip before the photo's address is known.
- The picker: client rendering's picker worked last, but never ignored a tap. The other four drew the picker 114 to 119 ms before it worked. Why it matters: that gap is the trip for the script, plus hydration.
And INP?
Interaction to Next Paint, or INP, measures how long a tap waits for the next frame. It hardly moved. Every tap in every load got its next paint within 24 ms. Most were under 16 ms, the least that the browser's Event Timing reports.
// Asha tapped 50 g every 50 ms, from the moment it was drawn. The middle tap load of each build.const nothing = { Client: 0, Server: 3, Static: 3, Revalidate: 3, Islands: 3 }; for (const [build, taps] of Object.entries(nothing)) console.log(`${build}: ${taps} taps did nothing`);- Line 2 holds how many taps did nothing, in the middle tap load of each build.
- Line 4 prints
Client: 0 taps did nothing, thenServer: 3 taps did nothing. The other three builds print 3 too.
Those taps didn't hurt INP. Each got its next paint quickly: the same picker, with the same price. Lesson 23.3 met this too. INP can't see a tap that did nothing.
Why was every tap fast? Little JavaScript ran while Asha tapped. In the first 3 seconds, the main thread was busy for 86 to 97 ms in every build. JavaScript ran for only 5 to 9 ms of it, the course's own notes included. No task was long. Why it matters: INP moves with the code that runs when a visitor taps. A strategy changes INP only through how much code it ships and runs. That's why web.dev says static rendering gives a lower INP "as long as you limit the amount of client-side JavaScript".
Pick a build to see all its numbers:
- First byte (TTFB)165.9 ms
- First text or image (FCP)232 ms
- 50 g drawn793.7 ms
- Picker works from768.9 ms
- Photo on screen (LCP)1,052 ms
- Taps that did nothing0
- Slowest tap (INP)under 16 ms
- JavaScript sent715 bytes
- HTML sent1062 bytes
- Main thread busy, first 3 s96.5 ms
- Of that, running JavaScript9 ms
- Price shown for 100 g£4.80
Pick a build. The times are in ms after Asha opened the page, from the middle of 5 watched loads, and the taps from the middle of 5 tap loads. Sizes are the gzipped bytes that travelled.
Picking a build for each page
Ravi doesn't have to pick one build for his whole shop. web.dev says "you can always choose to use server-side rendering for some pages and not others." Netflix, it says, server-renders its "relatively static landing pages". For "interaction-heavy pages", it prefetches the JavaScript.
Most frameworks decide page by page. In Next.js, a page is prerendered, built ahead, by default. A page that uses a request-time API, such as cookies() or headers(), is rendered for each request instead.
A restaurant kitchen doesn't cook every dish the same way. Bread is baked in the morning, for everyone. Soup sits in a big pot and is topped up when it runs low. A steak is cooked for one diner, when she orders it. It's one menu, but each dish gets the way that suits it.
- In real life: The menu
- In JavaScript: Ravi's whole site
- In real life: Each dish
- In JavaScript: Each page, or route
- In real life: Bread baked in the morning
- In JavaScript: A static page
- In real life: Soup topped up when it runs low
- In JavaScript: A page with revalidation
- In real life: A steak cooked when one diner orders it
- In JavaScript: A page rendered for each visit
Ask three questions about each page:
- Is it the same for everyone? If not, like a cart, one kept copy can't be right. web.dev names pages that need personalization as a poor fit for static rendering.
- How old may it be? If a copy a minute old is fine, keep it and revalidate. If not, build it per visit, or rebuild it when the data changes.
- How much of it moves? Send code only for the parts that do.
Here is what that means for Ravi's pages. Read each row across:
| Page of Ravi's shop | What it needs | A build that fits |
|---|---|---|
| The page about the shop | It's the same for everyone. It changes once a year. | Static. Build it ahead, and send the kept copy. |
| The list of teas | It's the same for everyone. It changes when Ravi adds a tea. | Static with revalidation. A visit or two may see the old list. |
| A tea's page | It's the same for everyone, and its price changes now and then. Only the buy box moves. | Static with revalidation, with the buy box as an island. |
| Search results | They depend on the words each visitor types. | Server rendering. There's nothing to build ahead. |
| The cart | It's different for every visitor. | Server rendering. One kept copy can't be right for everyone. |
Then measure, as this lesson did. web.dev ends its guide with the same advice: "measure and understand what your bottlenecks are."
Which build for which page?
Here are seven pages of a tea shop. Sort each one by the build that suits it:
- A page about the shop's history
- A brewing guide Ravi edits once a year
- The list of teas, which gains a tea now and then
- A tea's page, whose price changes a few times a month
- Search results for the words a visitor typed
- A visitor's own cart
- A blending tool where visitors drag leaves into a pot and watch the mix change
Sort each page by the build that suits it.
Common mix-ups
- "Server rendering is always faster than client rendering." No. It showed the photo sooner here. But its first byte came about 250 ms after every other build's, because the server built the page first.
- "A page that looks ready is ready." No. In four builds, the picker was drawn more than 110 ms before it worked. Asha's first three taps did nothing.
- "Static pages can't change." No. With revalidation, the server rebuilds a page in the background, and the next visitor gets the new one.
- "With revalidation, every visitor sees the newest price." No. The first visit after the page goes stale still gets the old copy. Asha saw £4.50.
- "Islands always make a page faster." No. Here, the picker worked at the same time as on the static page. Islands skip the code for the still parts, so they help most when that code is big.
- "A good INP means every tap worked." No. Taps that did nothing finished fast, so INP stayed low while the picker ignored Asha.
- "A site must use one strategy everywhere." No. Most frameworks choose page by page.
Practice exercises
Answer first, then use the hints.
Ravi's database gets 400 ms slower. What does the first line print?
// If Ravi's database took 400 ms longer. The recorded first bytes, in ms:
const server = 418.7;
const staticBuild = 167;
const slower = 400;
console.log(`Server: ${server + slower} ms`);
console.log(`Static: ${staticBuild} ms`);Server: 818.7 ms. The server build pays for the database on every visit, so its first byte moves by the full 400 ms. The static page was built ahead, so its first byte stays at 167 ms.
This small model of revalidation keeps one price. What does the last line print?
let kept = { price: "£4.50", builtAt: 0 };
let database = "£4.50";
function visit(second) {
const shown = kept.price;
if (second - kept.builtAt > 60) kept = { price: database, builtAt: second };
return `At ${second} s: ${shown}`;
}
console.log(visit(30));
database = "£4.80";
console.log(visit(70));
console.log(visit(75));At 75 s: £4.80. The visit at 70 s still got the old price, and its rebuild kept the new one. The visit at 75 s gets the fresh page.
In the server build's middle load, how long was the main thread busy in the first 3 seconds, in ms?
88.3 ms. Only 6.3 ms of it was JavaScript. The rest was the browser's own work on the page, such as styles and layout.
On Asha's visit, when did Ravi's server send the kept page, in ms after her request arrived?
166.1 ms after her request arrived: the 165 ms trip, and almost nothing else. The rebuild was still running, so the kept page left with the old price.
Open the course's copies of two builds: client.html and static.html. Turn JavaScript off in DevTools, and reload both. Which one still shows the reviews?
static.html. Its HTML holds the whole page, so the reviews show with JavaScript off. client.html shows only the green header, because app.js draws everything else. web.dev suggests this test to tell a static page from one that needs JavaScript.
Ravi changed his revalidating rule. On a visit that finds the page too old, which of the five builds does this one now act like?
async function revalidatingPage() {
if (Date.now() - kept.builtAt > 60_000) {
kept.builtAt = Date.now();
kept.html = await build(database.price);
}
return kept.html;
}build(database.price).then((html) => (kept.html = html));Server rendering. With await, a visit that finds the page too old waits for the whole build, so its first byte pays the 250 ms. Start the build without await, and send the kept page at once.
Check your understanding
For each question, ask yourself where the page was built, and when.
Question 1 of 7What does the first line of the opening example print?
Read the code, then predict// Two moments of Asha's visit, in ms: the photo on screen (LCP), and the first moment 50 g worked. // The middle of 5 loads of each build. const builds = [ ["Client", 1052, 768.9], ["Server", 712, 604.8], ["Static", 460, 351.3], ["Revalidate", 464, 355.4], ["Islands", 460, 348.9], ]; for (const [build, photo, works] of builds) console.log(`${build}: photo ${photo} ms, picker ${works} ms`);Choose an answer to see the explanation.
Question 2 of 7Why did the server build's first byte come later than the static build's?
Choose an answer to see the explanation.
Question 3 of 7In the recording, why was the client build's photo the last to appear?
Choose an answer to see the explanation.
Question 4 of 7The revalidating page has gone stale, and Ravi has changed the price. What does the next visitor get?
Choose an answer to see the explanation.
Question 5 of 7In the recording, why did the islands build's picker work at about the same time as the static build's?
Choose an answer to see the explanation.
Question 6 of 7In the recording, which build had no taps that did nothing?
Choose an answer to see the explanation.
Question 7 of 7Ravi's cart page shows each visitor their own teas. Which build fits it?
Choose an answer to see the explanation.
Key takeaways
- A rendering strategy decides where and when the HTML is built. That moves the wait between TTFB, LCP and the first tap that works.
- Server rendering paid its 250 ms build in TTFB on every visit. A static page paid it once, ahead of time.
- Client rendering chained four trips before the photo, so its LCP came last. But its picker never ignored a tap.
- Hydrated pages looked ready more than 110 ms before they worked here. With a framework, the gap grows.
- Revalidation sends the kept page at once and rebuilds it in the background. One visit sees the old data.
- Islands skip the code for the parts that never move. They help as much as that code weighs.
- Pick per page: is it the same for everyone, how old may it be, and how much of it moves?
Remember the one-liner.
Build the HTML as early as the page allows, and send code only for the parts that move.
Sources
The facts on this page come from these docs and standards:
- Rendering on the Web, web.dev.
- How to implement Incremental Static Regeneration (ISR), Next.js.
- RFC 5861: HTTP Cache-Control Extensions for Stale Content, IETF.
- Islands Architecture, Jason Miller.
- Islands architecture, Astro.
- Template directives reference: client directives, Astro.
- Glossary: dynamic rendering and prerendering, Next.js.
Coming next: Streaming HTML. The server build sent nothing until the whole page was ready. Streaming sends the parts that are ready first.