CMD Guide
HomeSystem DesignScalable Systems (Advanced Topics)

What are HTTP Conditional Requests ETag, If‑None‑Match, Last‑Modified and How They Reduce Load

A conditional request works by having the client echo back a validator it was given earlier — an opaque ETag token or a Last-Modified timestamp — so the origin can compare that validator against the resource's current version and, when they match, answer with a bodyless 304 Not Modified that tells the client to reuse bytes it already holds instead of re-transmitting them.

The server first hands out a validator alongside the full 200 OK. The browser stores it with the cached bytes. On the next fetch the browser turns an ordinary GET into a conditional GET by attaching the saved validator in a precondition header:

The server evaluates the precondition. Unchanged → 304, no body. Changed → 200 with the fresh body and a new validator. The check itself is cheap; the win is that unchanged responses skip the payload entirely.

diagram
diagram

A worked trace, with real bytes

Suppose /styles.css is 48 KB and the origin sets Cache-Control: max-age=60. Follow one browser across three visits:

#What the browser sendsServer decisionOn the wire
1 — coldGET /styles.css (no validators)Serve fresh copy200 OK + 48 KB body + ETag: "a1b2", Last-Modified: Tue, 15 Sep 2025 11:00:00 GMT
2 — within 60 sNothing — entry is still freshNot consulted0 bytes. Served straight from cache; no request leaves the machine
3a — stale, unchangedIf-None-Match: "a1b2"Current ETag is still "a1b2" → match304 Not Modified, ~180 bytes of headers, no body. ~99.6% of the transfer avoided
3b — stale, changedIf-None-Match: "a1b2"Current ETag is now "c3d4" → mismatch200 OK + new 48 KB body + ETag: "c3d4". Cache is replaced

The crucial subtlety the naive mental model misses: visit 2 sends nothing, but visits 3a/3b both pay one full round-trip. A 304 collapses the payload, not the request. On a 40 ms link, a revalidation that returns 304 still blocks that resource for ~40 ms — cheap versus 48 KB, but not free. That distinction drives the whole selection story below.

ETag vs Last-Modified, and strong vs weak

An ETag is an opaque token the server picks to name a specific representation — usually a hash of the bytes or a version number. It carries a strength flag:

Last-Modified is a wall-clock timestamp. It is a weak validator by nature: HTTP-date has one-second resolution, so two edits in the same second look unchanged, and it depends on the server's clock and filesystem mtime being trustworthy. It also can't tell "rewritten with identical content" from "unchanged."

Both are used together in practice — browsers commonly send If-None-Match and If-Modified-Since in the same request, and per RFC 9110 the server evaluates If-None-Match first and only falls back to the date when no ETag is present.

DimensionETagLast-Modified
BasisContent fingerprint / version chosen by serverFilesystem mtime / clock
PrecisionByte-exact (strong) or semantic (weak)1 second; blind to sub-second edits
ComparisonExact token matchDate comparison
Write headerIf-None-Match / If-MatchIf-Modified-Since / If-Unmodified-Since
CostServer must compute/store the tagFree — mtime already exists
Best forDynamic bodies, APIs, CDNs, concurrency controlStatic files with reliable mtime, single origin

How this fits with Cache-Control

Conditional requests are only half of HTTP caching. Cache-Control governs freshness; validators govern revalidation. They compose:

Two directives change when that revalidation happens:

So the levers are: raise max-age to eliminate requests entirely during the freshness window; rely on validators to stay correct once stale. The 304's residual round-trip cost is exactly why a long max-age is worth reaching for when you can tolerate a brief staleness window.

diagram
diagram

Pitfalls

When to use it — and when not

Reach for conditional requests when the URL is stable and can't carry a version — HTML documents, user-generated content, API responses — and you need correctness on change without re-transmitting unchanged bytes. Signals that point here: the resource changes unpredictably; the same URL must always serve the latest; you're behind a CDN or API gateway that keys on ETags.

Pick ETag when changes are frequent, sub-second, or content-based, or when you also want optimistic concurrency (If-Match on writes to reject lost updates). Pick Last-Modified for static files on a single origin where mtime is trustworthy and you want validation for free.

Trade-off vs the main alternative: immutable + fingerprinted URLs

For build artifacts, the stronger pattern is content-fingerprinted URLsapp.9f3c1a.css served with Cache-Control: max-age=31536000, immutable. The browser never revalidates; a change ships as a new URL referenced by freshly built HTML.

Choose conditional requests when the URL must stay constant and correctness-on-change matters; prefer immutable + fingerprinted URLs for versioned static assets you build; and remember they combine — fingerprinted assets for the shell, conditional revalidation for the HTML that points at them.

Takeaways


Sources: MDN Web Docs — "HTTP conditional requests," ETag, If-None-Match, Last-Modified, and "HTTP caching"; RFC 9110 (HTTP Semantics) §8.8 (validator fields) and §13 (conditional requests); Google web.dev, "Prevent unnecessary network requests with the HTTP Cache"; Apache httpd FileETag documentation; DesignGurus, "Caching in System Design." Re-authored/Deepened for this guide.

🤖 Don't fully get this? Learn it with Claude

Stuck on What are HTTP Conditional Requests ETag, If‑None‑Match, Last‑Modified and How They Reduce Load? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **What are HTTP Conditional Requests ETag, If‑None‑Match, Last‑Modified and How They Reduce Load** (System Design) and want to truly understand it. Explain What are HTTP Conditional Requests ETag, If‑None‑Match, Last‑Modified and How They Reduce Load from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **What are HTTP Conditional Requests ETag, If‑None‑Match, Last‑Modified and How They Reduce Load** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **What are HTTP Conditional Requests ETag, If‑None‑Match, Last‑Modified and How They Reduce Load** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **What are HTTP Conditional Requests ETag, If‑None‑Match, Last‑Modified and How They Reduce Load** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes