Doodh chahiye? Pehle fridge (browser cache). Phir mohalle ki dairy (CDN). Phir godown (server). Last resort: gaay (database). The fastest request is the one that never reaches the gaay.
Model: a cached page is fetched from origin about once per edge per TTL. CloudFront also does request collapsing — when thousands of people miss the same object at the same instant, it sends one request to origin and makes the rest wait for it. Assumes ~50 ms of server work per origin request.
| Payload | Original | gzip | deflate | brotli | Saved |
|---|---|---|---|---|---|
| Compressing… | |||||
Text (HTML, JS, CSS, JSON) is repetitive, so it shrinks massively. JPEG/PNG/WebP are already compressed — gzipping them wastes CPU.
In DevTools, look for content-encoding: gzip or br (brotli) in the Response Headers.
Real example: pw.live's homepage HTML — 616 KB, sent as 137 KB with gzip (measured 24 Sep 2026).
| File | Cache-Control | Why |
|---|---|---|
app.3f9a1c2e.js — hashed JS / CSS / fonts | public, max-age=31536000, immutable | The name changes whenever the content changes. Cache it for a year. |
index.html — the page | no-cache for browsers (+ short s-maxage at the CDN) | Always check for a new deploy. It's the file that points at the new hashed files. |
/api/batches — same for everyone | public, s-maxage=60, stale-while-revalidate=300 | The CDN absorbs the crowd; nobody ever waits for a refresh. |
/api/me — personal | private, no-store | Never shared, never stored. Otherwise Priya sees Rahul. |
logo.png — no hash in the name | max-age=86400, or hash it too | Or accept that the new logo takes a day to show up. |
no-cache ≠ don't cache. no-cache = "keep it, but check with me before using it" (a cheap 304).
no-store = "don't keep it at all". The names are terrible; the difference matters.