Cache lab · har baar gaay tak mat jao 🐄

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.

A · The doodh supply chain

Pick a story above — or drive it yourself with the buttons below.

Cache-Control:

🧊 Rahul's fridge

browser cache · 0 ms

🧊 Priya's fridge

browser cache · 0 ms
→

🏪 Mohalle ki dairy

CDN edge (e.g. CloudFront, Mumbai) · +25 ms
→

🏭 Godown

app server + its cache · +120 ms
→

🐄 Gaay

database — the truth · +250 ms
Simulated clock: 10:00:00
0requests
0reached the gaay 🐄
0 KBover the network
0got an old version
0saw someone else's data

B · Result day: everyone refreshes at once

Students in 1 minute: CDN edges (cities):
Result page header:

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.

Requests that reach our servers
—

C · Compression — measured right now in your browser

PayloadOriginalgzipdeflatebrotliSaved
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).

D · Which header for which file

FileCache-ControlWhy
app.3f9a1c2e.js — hashed JS / CSS / fontspublic, max-age=31536000, immutableThe name changes whenever the content changes. Cache it for a year.
index.html — the pageno-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 everyonepublic, s-maxage=60, stale-while-revalidate=300The CDN absorbs the crowd; nobody ever waits for a refresh.
/api/me — personalprivate, no-storeNever shared, never stored. Otherwise Priya sees Rahul.
logo.png — no hash in the namemax-age=86400, or hash it tooOr 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.