Web Performance
Measure what a visitor actually sees and feels, then read reports, waterfalls and traces to find what is slow. Cut bytes and requests, keep the main thread free, stop the page jumping, and hold the gains with budgets and real-user data.
- Intermediate
- 4 units, 12 lessons, 156 exercises
- Text, HTML, JavaScript
- Builds on How Browsers Work
Unit 01 · 3 lessons
What fast means
Speed is what the user sees and feels
- 01User-centred metrics
Three numbers for what a visitor sees and feels
- 02Lab and field
One test machine against thousands of real visits
- BOSSRead a report
One product page: find what is slow and rank the fixes
Read the unit guide
A page is fast when the person using it experiences it as fast. "Everything finished loading" is not that moment: a page that shows its article at one second and keeps fetching for five more feels quicker than one that stays white for four. So performance is measured from the user's side, with three questions. Has the main content appeared? Does the page react when I touch it? Does it stay where it was?
The Core Web Vitals put a number on each. Largest Contentful Paint (LCP) is the time from the start of navigation until the largest image or text block in the viewport is drawn. Interaction to Next Paint (INP) watches every tap, click and key press and reports about the slowest: the wait before the handlers could start, the handlers themselves, and the time until the next frame is painted. Cumulative Layout Shift (CLS) scores how much visible content jumps: each shift is the share of the viewport affected times how far things moved, and CLS is the worst burst of shifts.
web.dev defines these metrics and currently calls a page good when LCP is 2.5 s or less, INP is 200 ms or less and CLS is 0.1 or less, each judged at the 75th percentile of visits, on phones and on desktops separately. A percentile is used because an average hides the slow tail, and the slow tail is real people.
There are two ways to measure. A lab test loads the page once on one machine with fixed settings: repeatable, detailed, possible before release, but it is one device with a cold cache and nobody tapping. Field data is collected in real visitors' browsers: every phone, network and cache state, but it arrives after release and says what happened, not why. The field tells you what to fix, the lab helps you find the cause and check the fix.
Read a report in a fixed order: the number, then the element or task behind it, then why that was late, then the fix. LCP splits into four parts with no gaps: time to first byte, the delay before the LCP resource is requested, the time to download it, and the delay until it is painted. A compressed image only shortens the download part, so find out which part is big before choosing a fix.
Unit 02 · 3 lessons
Loading
The fastest request is the one never made
- 01Fewer bytes
Compress text, right-size images, skip what is off screen
- 02Caching
Reuse a copy, check a copy, and name files so both are safe
- BOSSThe first paint
One article page: clear the path from HTML to pixels
Read the unit guide
Loading work has an order of payoff: do not make the request at all, then make it smaller, then make it arrive sooner. A copy already in the browser costs nothing. A file a quarter of the size downloads in about a quarter of the time. A file that must come over the network should at least start early and travel a short way.
Text shrinks well. Minifying strips spaces, comments and long names from code that still runs the same, and the server then compresses the bytes with gzip or Brotli: the browser lists what it can unpack in Accept-Encoding, the server answers with Content-Encoding. Photos are already compressed, so their savings come from elsewhere: send no more pixels than the screen will show, in a modern format. srcset lists the same image at several widths and sizes tells the browser how wide it will be drawn, so the browser can pick the smallest file that is still sharp on this screen. loading="lazy" leaves an image unrequested until the user scrolls near it, which is right for everything except what the first screen shows.
Caching is how a request is never made. Cache-Control: max-age=N makes a response fresh for N seconds, and a fresh copy is reused without contacting anyone. A stale copy is revalidated: the browser quotes its ETag in If-None-Match and the server answers 304 Not Modified with no body if nothing changed. no-cache means "store it, but check every time"; no-store means "keep no copy".
The standard recipe joins the two. Build tools put a hash of the content in each file name, so a changed file is a new URL. Hashed files can then be cached for a year and marked immutable, while the HTML that names them is no-cache. A CDN adds a shared cache on servers near the user, so even a first visit travels a short distance.
The first paint waits for what the browser needs to draw correctly: every stylesheet in the head blocks rendering, and a plain script stops the parser before the content below it. Mark scripts defer, give print styles media="print", open connections to other origins early with preconnect, announce late-discovered files with preload, and inline the small part of the CSS that the first screen needs. Web fonts should not hide text: font-display: swap shows a fallback font at once.
Unit 03 · 3 lessons
After load
A page that loaded can still be slow
- 01The cost of JavaScript
Why a script costs more than an image of the same size
- 02Staying responsive
Long tasks, yielding, debounce, throttle and workers
- BOSSSmooth rendering
One janky product list: layout thrash, shifts and long lists
Read the unit guide
Once the page is on screen the scarce resource is no longer the network. It is the main thread: one thread that runs your JavaScript, handles taps, computes styles and layout, and paints. While it is busy with one of those it does none of the others, so a page that has finished loading can still ignore a tap for half a second.
JavaScript is the most expensive kind of byte. An image is downloaded and decoded; a script is downloaded, parsed, compiled and executed, and the last three happen on the visitor's CPU, which on a mid-range phone is several times slower than a laptop. Send less of it: split the bundle by route so each page loads its own code, load rarely used features with import() when they are first needed, let the bundler drop exports nothing imports, and treat third-party scripts as code you are responsible for.
A task over 50 ms is a long task. A tap that arrives during one waits for it to finish, and that wait is the input delay in INP. The cure is to yield: cut the work into chunks and hand the thread back between them, so pending input runs in the gap. A timer starts a new task and so yields; a resolved promise continues in the same task and does not. Work that needs no DOM can leave the main thread altogether in a web worker.
Some events fire far more often than you need to react. Debounce waits until they stop for a while and runs once (search as you type). Throttle runs at most once per interval while they keep coming (a scroll position). Both are a few lines around a timer, and code about time is tested on a clock you control, never by really waiting.
Rendering has its own traps. Reading a size (offsetWidth, getBoundingClientRect()) after changing a style forces the browser to run layout at once; in a loop that is one layout per item, so read everything first and write afterwards. Anything that changes size after it is drawn pushes its neighbours: give images width and height and reserve a box for late content. Animate transform and opacity, which need neither layout nor paint, and never create ten thousand rows when fifteen are visible.
Unit 04 · 3 lessons
In practice
Performance is a feature you keep, not a project you finish
- 01Where the HTML is made
Static, server and client rendering, hydration, the edge
- 02Budgets and monitoring
A limit per page, a check in CI, numbers from real users
- BOSSFix a site
One recipe page, five problems, fixed in order of payoff
Read the unit guide
Where the HTML is made decides most of what follows. Static rendering builds each page once, ahead of time, and serves the same file to everyone from a cache near them: nothing is faster. Server rendering builds the HTML for each request, so it can be fresh and personal, at the price of server work before the first byte. Client rendering sends an almost empty page and builds the content in the browser, so nothing useful shows until the script has downloaded and run.
Server-rendered pages usually still ship the app's JavaScript. The HTML arrives looking finished, but its buttons have no handlers until the script runs and attaches them: hydration. Between the paint and the end of hydration the page looks ready and is not, and hydration itself is a long task. Send less JavaScript to hydrate, or hydrate only the parts that are interactive. Streaming helps at the other end: the server sends the top of the page while it is still working on the rest, so the browser can paint and start fetching files early.
Running code at the edge puts the renderer a few milliseconds from the user. It pays off when the data is nearby too. A page rendered at the edge that makes two queries to a database on another continent can be slower than one rendered beside that database.
Speed is lost in small steps: ten kilobytes here, one more script there, none of them worth an argument. A performance budget is a limit agreed in advance, per page, on things that can be counted: kilobytes of JavaScript, image weight, requests, a lab LCP. A check in CI compares every build with it and fails the build that goes over. Lab numbers are noisy, so compare a median of several runs, not one.
The lab guards what you can measure before release; only the field tells you what users got. Collect the vitals from real visits, store them by page, device and release, and watch the 75th percentile. When you fix something, work in order of payoff, change one thing at a time, and measure in the field afterwards. The prediction is not the result.
Learn Web Performance on your phone.
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.