Prologue — The Journey of a Single Click
“Any sufficiently advanced technology is indistinguishable from a page that loaded fast.”— not quite Arthur C. Clarke
It is 9:04 p.m. in a suburb of Pune. Priya is on her sofa with a ₹12,000 Android phone, a cup of chai cooling on the armrest, and a WhatsApp group that will not stop. Someone has posted a link to a photo essay. She taps it.
Four seconds later she is reading. Or she is staring at a white screen, then a layout that jumps, then a button that doesn’t respond, and she has gone back to WhatsApp. Which of those happens is decided by hundreds of small things, almost none of which are “the code” in the sense that you and I learned to write code.
This book is about those small things. The build step that decided how many bytes she downloads. The CI pipeline that stopped a broken build reaching her. The DNS lookup, the TLS handshake and the CDN edge in Mumbai. The HTML parser, the preload scanner, the style engine, the layout engine, the compositor and the GPU. The event loop that decides whether her tap gets answered in 80 ms or 800 ms. The metrics that measure all of this and send it, eventually, to Google.
Most developers learn to build features and keep building features. The glue gets learned by accident, if at all. And the glue is what separates a site that works from a site that feels good. Let’s follow the tap.
Before the tap: the bytes had to exist
Section titled “Before the tap: the bytes had to exist”Rewind three days. A developer — let’s say you — writes a React component in TypeScript in VS Code. It imports a date library from npm, uses JSX, uses a CSS module. None of that is something a browser can run. A browser understands exactly three languages: HTML, CSS and JavaScript (plus WebAssembly, images, fonts and media). It does not understand TypeScript, JSX, import dayjs from 'dayjs', or Sass.
So a build tool (Chapter 1) translates. It strips types, turns JSX into function calls, follows every import to build a dependency graph, throws away code nobody uses, splits the rest into chunks, minifies them, and stamps each file with a content hash so it can be cached forever. The date library came from a package manager (Chapter 2) that resolved a version range, wrote a lockfile, and — if you were unlucky in September 2025 — ran a post-install script written by an attacker.
You push. A CI server (Chapter 3) — a fresh, empty computer somewhere — checks out your commit, installs the exact locked dependencies, lints, type-checks, runs tests, builds, measures the bundle size, and runs Lighthouse. Green. A CD pipeline (Chapter 4) uploads the build to a VPS and a CDN, flips traffic to it, and keeps the previous version ready for a one-command rollback.
None of that has happened on Priya’s phone yet. All of it determines what happens there.
9:04:00.000 — the tap
Section titled “9:04:00.000 — the tap”Her thumb touches glass. The Android OS turns that into a touch event and hands it to Chrome’s browser process (Chapter 8), the privileged process that owns the address bar, the tabs and the network. Chrome sees a navigation to https://lumen.example.in/essays/monsoon.
Before going to the network, Chrome asks some questions. Is this page in the back/forward cache? No, she has never been here. Was it prerendered by Speculation Rules? No. Is there a service worker registered for this origin that might answer from a local cache? No. So, the network.
9:04:00.002 — who is lumen.example.in?
Section titled “9:04:00.002 — who is lumen.example.in?”Computers don’t route to names. They route to IP addresses. DNS (Chapter 5) is the internet’s phone book, and it’s a distributed, cached, hierarchical phone book. Chrome checks its own cache, then asks the OS, which asks a recursive resolver — probably her mobile carrier’s — which, if it doesn’t already know, walks the tree: root servers → the .in servers → the domain’s authoritative servers. On a cold path that’s several round trips. On her 4G connection one round trip is maybe 50–100 ms on a good evening and far worse on a congested tower. Today the resolver had it cached. Forty milliseconds.
9:04:00.045 — shaking hands
Section titled “9:04:00.045 — shaking hands”Now Chrome must open a connection to that IP. If it speaks HTTP/3, that’s QUIC over UDP, and the transport and encryption handshakes are combined into a single round trip. If it’s HTTP/2, it’s a TCP handshake (one round trip) and then a TLS 1.3 handshake (another). The server proves it is really lumen.example.in with a certificate signed by an authority her phone trusts.
Here is the first deep truth of this book, and it’s worth stopping on: on mobile, latency dominates bandwidth. Her connection might advertise 20 Mbps, but every round trip costs ~80 ms regardless of size, and a page load is a long chain of round trips. A 14 KB HTML file and a 140 KB one can take almost the same time to arrive. Ten sequential requests cannot.
9:04:00.210 — the edge
Section titled “9:04:00.210 — the edge”The IP she reached isn’t a server in a data centre in Virginia. It’s a CDN edge (Chapter 6) in Mumbai, one of hundreds of identical-looking machines around the world that all answer for the same IP via anycast. The edge looks at the request, checks its cache, and finds the HTML. Is it allowed to serve it? That depends on the Cache-Control header the origin sent last time. The HTML was marked s-maxage=60, stale-while-revalidate=600, so the edge serves it immediately and refreshes it in the background.
If it hadn’t been cached, the edge would have gone to the origin — your VPS, running Node behind nginx — which would have rendered the HTML (Chapter 7). Whether that HTML was rendered on the server at request time (SSR), at build time (SSG), or is an empty shell that JavaScript fills in on the phone (CSR) is one of the most consequential architectural decisions you’ll make, and it was made months ago in a meeting.
Time to first byte on her phone: about 260 ms. Not bad.
9:04:00.260 — the parser and its scout
Section titled “9:04:00.260 — the parser and its scout”The HTML streams in. Chrome hands it to a renderer process — a sandboxed process that can’t touch her files — and its main thread begins parsing (Chapter 9). The parser builds the DOM tree as it goes. But it has a problem: when it meets a classic <script> tag, it must stop, because that script might call document.write and change everything after it.
So Chrome cheats, brilliantly. A preload scanner races ahead through the raw HTML, looking only for URLs — stylesheets, scripts, images, fonts — and starts fetching them early. This one optimization is worth more than most of the “performance tips” you’ve ever read, and much of good loading performance is about not hiding things from it.
CSS is render-blocking: the browser won’t paint until it has the CSS, because painting unstyled content and then restyling it would be worse. Scripts marked defer or type="module" download in parallel and run after parsing. Scripts marked async run whenever they arrive.
9:04:00.900 — first pixels
Section titled “9:04:00.900 — first pixels”With DOM and CSS in hand, the main thread runs style (which rules apply to which elements), layout (where everything goes and how big it is), and paint (recording lists of drawing commands). Then the work leaves the main thread: the compositor thread splits the page into layers and tiles, raster threads (often using the GPU) turn drawing commands into pixels, and the GPU process composites them into a frame. Chapter 10 walks this pipeline stage by stage, because it is where “jank” lives.
The first time anything appears is First Contentful Paint. When the biggest thing in the viewport — the hero photo — appears, that’s Largest Contentful Paint. On Priya’s phone the hero image was discovered late (it was lazy-loaded by mistake), so LCP is 3.1 s. “Needs improvement.” Chapter 16 will teach you to break that 3.1 s into four parts and fix the right one.
9:04:02.400 — the tap that didn’t answer
Section titled “9:04:02.400 — the tap that didn’t answer”Priya sees a “Save to reading list” button and taps it at 2.4 s. Nothing happens for almost half a second. Why? Because at that moment the main thread was busy running a 450 ms chunk of JavaScript — hydrating the React app (Chapter 7) — and the browser cannot run her click handler until that task finishes. There is one main thread. It is a single cook. While the cook is chopping onions, nobody’s order gets taken (Chapter 11).
That delay is measured by Interaction to Next Paint — the time from her tap until the next frame shows a response. Her INP for this visit is 520 ms. That’s “poor.”
Meanwhile, the hero image finally arrives and pushes the paragraph she was reading down by 200 px. That’s a layout shift, measured by CLS. Hers: 0.18. Also “needs improvement.”
9:04:05 — the measurement leaves the phone
Section titled “9:04:05 — the measurement leaves the phone”A few kilobytes of JavaScript from the web-vitals library have been watching all of this. When she switches back to WhatsApp, the page becomes hidden, and the library sends a beacon (Chapter 17) to your analytics endpoint: LCP 3.1 s, INP 520 ms, CLS 0.18, device memory 4 GB, effective connection type 4g.
Chrome itself also records it, anonymously, for users who have opted in to usage statistics. Those numbers flow into the Chrome UX Report (CrUX), aggregated over 28 days. Google Search uses the 75th percentile of those field numbers as one (modest) input into ranking (Chapter 22). Your observability stack (Chapter 23) notices that p75 INP on mobile crossed 500 ms after Tuesday’s deploy and pages someone.
That someone opens the Performance panel in DevTools (Chapters 10 and 16), sets CPU throttling to 4× (or better, plugs in a real Android phone — Chapter 17), records, and sees the red-cornered long task. They split the hydration work, yield to the main thread, move the hero image out of lazy loading and add fetchpriority="high", and ship. A week later CrUX shows p75 LCP 2.2 s, INP 160 ms, CLS 0.02.
Priya never knows any of this happened. She just notices that the site feels “nice.” That is the whole job.
What each part of the book does
Section titled “What each part of the book does”Part I — From Your Editor to the Internet. How your code becomes bytes, how those bytes get tested, shipped and delivered across the planet, and where HTML should be made.
Part II — Inside the Browser. The browser as an operating system: processes, the loading sequence, the rendering pipeline frame by frame, the event loop, storage, security, the API surface, and the accessibility tree.
Part III — Performance, Measured. What every metric means, which numbers are good, why your laptop lies, how to test on real phones, and a playbook for fixing things — anchored by a real audit of a real project.
Part IV — Motion and Graphics. Animation that feels right within a 16 ms budget, and the GPU from Canvas 2D through WebGL to WebGPU.
Part V — Found, Observed and Grown Up. SEO plumbing, observability, and a capstone on thinking and communicating like a staff engineer.
The running project: Lumen
Section titled “The running project: Lumen”Throughout the book’s labs you’ll build and operate Lumen, a small photo-essay site. It starts in Chapter 1 as a single index.html with no tooling at all. By Chapter 4 it’s a Next.js app deployed to your own VPS and to Cloudflare. By Chapter 17 you’ll have profiled it on a real phone. By Chapter 20 it has a WebGL “lens” hero. By Chapter 23 it pages you when it breaks. By the end you’ll have built, shipped, measured and defended every layer of it — which is exactly what staff engineers are expected to be able to talk about.
How to read this book
Section titled “How to read this book”Each chapter opens with a story, because a mental model sticks better than a definition. Then the concept, why it exists, what the world would look like without it, how it works, how to do it well, and what happens when it goes wrong. Every chapter ends with a 🧑🏫 Whiteboard Version — the three to five boxes you’d draw to explain it in sixty seconds — then a short self-quiz and exercises in three tiers: warm-ups, hands-on labs on Lumen, and staff-level challenges.
Read Part I and II in order. After that, jump around. Chapter 10 is the deepest in the book, on purpose: it’s where most of what “feels janky” actually comes from.
Ready? Let’s go back to the editor, and to the first lie: that what you write is what ships.