Skip to content
Draft — this lesson has not been reviewed yet. Its facts are sourced, but read it with a critical eye.

Frontend architecture

The salon platform has three kinds of page: a marketing site, a public page per salon reached from a link in a chat message, and a dashboard where each owner manages her day.

The team builds all three as one app in the browser. The server sends a near-empty HTML file and one JavaScript file that draws every page, fetches data from the API and handles every tap. On a laptop over office Wi-Fi it feels instant. It works.

Then a customer taps a salon’s link on a mid-range Android phone on a mobile network. Lesson 1.1 counted the round trips. This time count the bytes. The script has grown to 600 KB, because the dashboard’s charts, calendar and settings are all in it. Google’s Lighthouse tool tests mobile pages at 1.6 Mbps (checked 2026-11-29). 600 KB is 4,800 kilobits, and 4,800 ÷ 1,600 is three seconds to download, with a white screen the whole time. Then the phone has to run all of it, and Lighthouse runs that test with the processor slowed four times, to stand for a cheaper phone. Only then does the script ask the API for the salon’s details. The customer wanted a price list and a “Book” button. She paid for a calendar she will never open.

Search engines get the same near-empty HTML, which says nothing about the salon.

What broke? One way of building pages was used for three very different visitors. The customer arrives cold, once. The owner arrives warm, every day. Nobody chose where each page’s HTML should be made, or how much code each visitor should carry.

Terms used in this lesson:

  • The DOM is the browser’s live tree of the page.
  • Rendering is turning data into HTML.
  • The main thread is the browser thread that runs scripts, lays out the page and handles taps. While a script runs on it, a tap waits.
  • A bundle is a JavaScript file a build tool makes by joining many source files.
  • A single-page application (SPA) “loads only a single web document, and then updates the body content of that single document via JavaScript APIs such as Fetch” (MDN).

Every page answers one question first: where is its HTML made? At build time, on the server for each request, or in the browser. Pick by the visitor: how often they come, whether the page is the same for everyone, and how fresh it must be. Then remember that every kilobyte of JavaScript is paid for twice: once on the network, and again on the phone’s processor.

The salon’s public page on a slow phone, built in the browser and then built on the server.

APIServerPhoneAPIServerPhoneClient-side renderingDownload and run the script. White screenScript builds the page. First content appears, and it worksServer-side rendering with hydrationFirst content appears. Taps do not work yetScript runs and attaches to the HTML (hydration). Now it worksGET /salonEmpty HTML and one large scriptGET salon detailsDataGET /salonGET salon details, inside the data centreDataFull HTML, plus a smaller script

The page appearing and the page working are two different moments.

The terms come from Google’s web.dev guide, Rendering on the web (updated January 2026).

Client-side rendering (CSR) is “rendering an app in a browser, using JavaScript to modify the DOM”: the SPA from the opening. After the first load a new screen needs only data, so it feels quick. The cost: “the amount of JavaScript required tends to grow as an application grows”. Every visitor pays for every feature unless the code is split.

Server-side rendering (SSR) is “rendering an app on the server to send HTML, rather than JavaScript, to the client”. The server fetches data and builds the page for each request, which “avoids additional round trips for data fetching and templating on the client”. The cost: server work on every view, and “generating pages on the server takes time, which can increase your page’s TTFB” (time to first byte).

Static generation (SSG) builds the HTML once, at build time, and serves the same file to everyone. It gives a “consistently fast TTFB”, and the files can sit on a CDN (lesson 1.9). The cost: it “must generate individual HTML files for every possible URL”, and a page that differs per visitor cannot be built ahead. Incremental static regeneration (ISR) rebuilds a page in the background after a time window; the Next.js docs note that the next request “will still return the cached (now stale) page”. Freshness of cached copies is lesson 2.4.

Hydration joins SSR to CSR: “running client-side scripts to add application state and interactivity to server-rendered HTML”. The server’s HTML shows the page; the script then attaches to it so the buttons work.

So what does each salon page want? The marketing site is the same for everyone: SSG. A salon’s public page is visited cold, often once, must be readable by search engines, and changes when the owner edits her prices: SSR, or SSG with regeneration if a short delay is acceptable. The dashboard is personal, behind a login and used all day; a slower first load buys quick screens after: CSR, as an SPA.

Hydration: the page that looks ready and is not

Section titled “Hydration: the page that looks ready and is not”

SSR shows content early. Does the page work early? No. web.dev: a hydrated page “can appear to be loaded and interactive, but can’t actually respond to input until the client-side scripts for components are executed … On mobile, this can take minutes”.

Why is the script still large? The server sends the HTML, “the source data used to compose that UI, and a complete copy of the UI’s implementation” (web.dev). The page arrives twice, once as HTML and once as code. And the two must agree: React’s docs say hydration “expects the rendered content to be identical with the server-rendered content. You should treat mismatches as bugs and fix them.” React’s example of an unavoidable one is a timestamp.

Three ideas shrink the gap:

  • Streaming SSR sends the page’s frame at once with a placeholder for the slow part. When its data is ready, React sends the rest “along with an inline <script> tag that replaces the loading fallback”.
  • Islands render the page as HTML and hydrate only “highly dynamic regions” (Jason Miller). The salon’s price list stays plain HTML; only the booking button is an island.
  • Ship less. Not every page needs a framework in the browser. Google’s advice is to “consider server-side rendering or static rendering over a full rehydration approach”.

Why is JavaScript worse than an image of the same size? A script is downloaded, then compiled and run on the main thread. The V8 team, who build Chrome’s JavaScript engine, wrote in 2019 that “the dominant costs of processing scripts are now download and CPU execution time. User interaction can be delayed if the browser’s main thread is busy executing JavaScript.”

How much is normal? The 2024 Web Almanac put the median mobile page at 558 KB of JavaScript, with roughly half of it unused during load. How much is acceptable? There is no standard. Alex Russell publishes a yearly budget. His 2026 edition (November 2025) models a 75th-percentile user at 9 Mbps and 100 ms RTT, and allows about 0.62 MiB of JavaScript for a script-heavy page to load in three seconds. His 75th-percentile figures for Nigeria are 3.1 Mbps and 190 ms. Budget for the users you actually have.

The fix is code splitting: “only send the code needed for the initial route”, using dynamic imports so the bundler cuts the app into chunks that load when needed (web.dev). The V8 post’s rule of thumb: “if a bundle exceeds ~50–100 kB, split it up”. The dashboard’s calendar, charts and settings become separate chunks, each loaded the first time the owner opens that screen. The public page carries none of them.

Repeat visits on slow networks: service workers and PWAs

Section titled “Repeat visits on slow networks: service workers and PWAs”

The owner comes back daily, sometimes on one bar of signal. Can the second visit skip the network?

A service worker is a script the browser runs on its own thread, apart from the page. MDN: it acts as a proxy server “between web applications, the browser, and the network”. It sees each request the page makes and decides how to answer. It needs HTTPS.

The usual SPA pattern is the app shell: the HTML, main script and styles every screen needs. The service worker saves the shell when it installs, so the next visit loads it from the phone and only data crosses the network. web.dev says this “can dramatically improve perceived performance on repeat visits”. The Workbox docs name the strategies for each kind of file:

  • Cache first: “If the asset is in the cache, serve it from there”, otherwise fetch. Right for files whose name changes with their content, such as calendar.3f9a1c.js, which never go stale.
  • Network first, falling back to the cache: right when fresh matters most, such as today’s appointments.
  • Stale-while-revalidate: answer from the cache and refresh it in the background, when a slightly old copy is fine.

A progressive web app (PWA) is “an app that’s built using web platform technologies, but that provides a user experience like that of a platform-specific app” (MDN). To be installable, with an icon on the home screen, it needs HTTPS and a web app manifest: a JSON file with the app’s name, icons and start address. MDN notes a service worker is not required to install, though most PWAs use one for offline support.

Which part do you fix first? Google’s Core Web Vitals (thresholds checked 2026-11-29) are judged at the 75th percentile of page loads, mobile and desktop apart:

Metric What it measures Good
Largest Contentful Paint (LCP) when the largest image or text block in view is drawn 2.5 s or less
Interaction to Next Paint (INP) how fast the page responds to taps, across the visit 200 ms or less
Cumulative Layout Shift (CLS) how much content jumps while loading 0.1 or less

INP replaced First Input Delay on 12 March 2024. In the lab, Lighthouse reports Total Blocking Time (TBT), “a proxy metric for INP” that measures how long the main thread was blocked during load (web.dev). Each metric points at a cause. A poor LCP on the CSR salon page means content waits on the script and the API. A good LCP with a poor INP is the hydration gap. CLS usually comes from images with no reserved space.

For search, Google renders JavaScript in a queue that “can take longer” than a few seconds, and recommends server-side or pre-rendering because “not all bots can run JavaScript”.

Roost, a booking platform for businesses that sell their time, builds a different frontend for each of its two kinds of visitor.

The problem. Customers reach a business’s booking page from a chat link, on a phone, with no account; the project treats 3G as its baseline. Owners and staff use a dashboard every day, signed in.

The public page. The landing page is rendered on the server, so it is always current. A business can be created, or change its details, and share its link the same minute, and the page carries facts that decide what the booking offers, so a stale copy could promise something the business no longer does. The booking steps after it run in the browser. The public app is installable, but its service worker caches nothing; it only shows a small offline page when a navigation fails. The reason is tenancy: the same path renders a different business for each host name, so serving a cached app shell for navigations could show one business’s page under another’s address.

The dashboard. The dashboard is an SPA, built to static files, with each screen its own chunk. It is installable, and its service worker precaches only the shell: the HTML, main script and styles, fonts and brand images. Screen chunks are cached, cache first, when the owner first opens them, safe because their names change with their content. When this was decided the build had 207 screen chunks totalling 3.9 MB, which precaching would have sent on every release to owners who open a handful of screens. The worker caches code, not the owner’s data.

The trade-off. The public page pays server time on every view for freshness and correct tenancy; the dashboard pays a slower first visit for fast later ones.

Honest about scale. Roost is early-stage. There are no recorded load-time or Core Web Vitals measurements for either app; the arithmetic in this lesson is an estimate. At larger scale the first question for the public page would be which parts can be cached per business without losing freshness, which lesson 2.4 takes up.

CSR, SSR or SSG. SSG is cheapest to serve and fastest to first byte, and costs freshness and personal content. SSR is fresh and personal, and costs server work per view and a slower first byte. CSR navigates quickly after the first load, and costs that first load, search visibility and every byte of code on every visitor. Choose per page: who arrives, how often, how fresh?

Split more or less. Smaller chunks mean less to download. More chunks mean more requests, and a chunk that loads another is a chain where each link costs a round trip. HTTP/2 from lesson 1.1 makes many requests cheap; it does not make a chain shorter.

Service worker or not. It makes repeat visits fast and works offline. It is also one more cache, on the user’s phone, that the team must update correctly on each release. For a page most visitors open once, the gain is small; for an app used daily, it is large.

“You are building a platform for restaurants: a marketing site, a public menu page for each restaurant that customers open from a QR code or a shared link, and a dashboard for staff to manage orders. Which rendering approach would you use for each, and why?”

Model answer

Marketing site: static generation. Same for everyone, changes rarely, needs search visibility. Build at deploy time and serve files from a CDN. Cost: a rebuild per edit.

Menu pages: server-side rendering. Visitors arrive cold, once, on phones. SSR puts the menu in the first response, off the slow link, readable by search engines. Keep client JavaScript to the order button, as an island if possible. Cost: server work per view and a slower first byte. Static pages regenerated every few minutes would be faster, and show a menu minutes old.

Staff dashboard: SPA. Signed in, personal, used all day, invisible to search. One slower first load buys fast screens. Split by screen so the order list does not carry the reports. On poor connections, add a service worker that caches the shell.

Check. LCP under 2.5 s and INP under 200 ms at the 75th percentile on mobile.

Rubric
  • Chooses per surface, not one approach for everything — 2
  • Defines SSG, SSR and CSR correctly in the answer — 2
  • Justifies each choice by visitor, frequency and freshness — 2
  • Names a cost for each choice — 2
  • Mentions bundle size or code splitting for the SPA, or a metric to verify — 2

Total 10. 8 or more is a pass.

The interviewer follows up: “You moved the menu page to SSR. LCP went from 4 seconds to 1.5. But on cheap Android phones, customers tap ‘Add to order’ and nothing happens for two or three seconds. What is going on, and what would you do?”

Model answer

Diagnosis: the hydration gap. The HTML arrives early, so LCP improved, but the buttons work only after the bundle downloads, runs and attaches. On a slow processor that keeps the main thread busy for seconds, so taps wait. INP and Total Blocking Time show it; LCP never will.

Fixes, cheapest first. Find what the bundle holds and remove what the menu page does not need. Split by route. Defer scripts not needed for ordering. Hydrate only the interactive parts, with islands or partial hydration, so the menu text needs no JavaScript. Fix hydration mismatches, which make the framework redo work.

Bridge the gap. Make the button a real form that posts to the server, so it works before the script arrives.

Cost. Less uniform code, and more requests.

Rubric
  • Explains that content visible is not the same as interactive — 2
  • Names hydration and the main thread as the cause — 2
  • Names the right metric (INP or TBT), not LCP — 2
  • Proposes reducing or splitting the JavaScript — 2
  • Proposes partial hydration, islands or a no-JavaScript fallback, with a cost — 2

Total 10. 8 or more is a pass.

Build one page three ways and measure each on a slow phone profile.

  1. Make a menu page: twenty items with prices and an “Add” button that updates a counter. Build it client-side only, server-rendered with hydration, and as plain server HTML with a few lines of script for the button.
  2. Predict which version has the best LCP and which the best TBT. Write it down.
  3. Run Lighthouse in Chrome DevTools in mobile mode (its defaults throttle network and processor). Record LCP, TBT and JavaScript bytes for each.
  4. Add a large library, such as a charting library, to the client-side version and measure. Then load it with a dynamic import only when a button is pressed. What changed?
  5. Add a service worker that caches the page and its script, cache first. Load the page, set DevTools to offline, and reload. Then change the script without changing its file name, and explain what the user sees.

Write one sentence per step on what surprised you.

Answer without notes.

  1. Define CSR, SSR, SSG and hydration in one sentence each. Where is the HTML made in each?
  2. One page is public, the same for everyone, and changes weekly. Another is personal and changes every minute. Which rendering approach suits each, and what does each cost?
  3. A 500 KB bundle is downloaded at 1.6 Mbps. How long does the download take? Why is that not the whole cost of the script?
  4. What does a service worker do? Which caching strategy suits a content-hashed script, and which today’s appointments? Why?
  5. Name the three Core Web Vitals and their “good” thresholds. A server-rendered page has a good LCP but a poor INP. What is the likely cause?