skipnothing/HTTP & Networking

Caching & Revalidation

Load https://example.com/logo.png twice in a browser and the first trip carries the full image. The second can be answered before the request ever leaves your machine, or come back with an empty body: same URL, very different cost.

  • ▸The fastest response never leaves: while a copy is fresh, your cache answers and the server never hears it.
  • ▸no-cache still caches; it only refuses to reuse a copy without checking first. no-store is what prevents storage.
  • ▸A 304 is a repeat request's win: same round trip, zero body bytes, because you already hold them.
BUILDS ON
01

Fresh copies skip the request

Fetch the logo a second time in a browser and the answer comes back almost instantly, and the origin (the server that owns the URL) gains no new line in its access log: it never saw the request. The first response arrived carrying Cache-Control: max-age=60, and your cache read that as a *freshness lifetime*, a window during which it may answer from its stored copy without asking anyone. Inside that window every repeat request is served locally. The fastest response is the one that never leaves your machine.

The subtle part is where the clock starts. max-age counts from the moment the origin *generated* the response, not the moment you received it. A response that spent time in an intermediary cache between you and the origin arrives with an Age already on the meter, so a copy handed to you with Age: 50 and max-age=60 is fresh for only ten more seconds. Push the age past the lifetime and the copy goes *stale*: your cache may no longer hand it out blindly.

THE FRESHNESS CLOCK

Keep going, sign up to unlock the rest

3 more parts in this topic, plus 23+ more topics in HTTP & Networking.

Sign up, it's freeSee the full HTTP & Networking