The Fastest Request Is the One That Is Never Sent, and Whether It Is Sent Was Decided by a Line of Text Last Week
Last timeThe Request and the Answer
Caching is not lore. Four headers and three questions decide, for any resource, whether a second visit sends nothing, sends a short question, or fetches the whole thing again.
Fresh or stale
A cache is a store of previous responses, and the only question it ever asks is
whether the stored copy may be used. That question has a precise answer derived
from two numbers.
- the freshness remaining, in seconds; while it is positive the copy may be used with no request
- the lifetime the server stated when it sent the copy
- the age of the copy, counted from when the server generated it rather than when this cache received it
While the remaining freshness is positive, nothing happens on the network. The
browser takes the copy out of its own store and renders it. No lookup, no
connection, no round trip, no server involvement whatsoever. This is the only
mechanism in the entire course that makes a request cost zero.
Asking only whether it changed
When the copy goes stale, the natural assumption is that it must be fetched
again. It does not.
A stale copy still carries the tag the server attached to it. Sending that tag
back turns the request into a question: do you still have this exact version.
If the answer is yes, the response is a status line and a few headers with no
body at all.
The lesson stops here
4 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents