8 min
  • Caching
  • HTTP
  • SSL/TLS
  • DNS

The second visit

Reload the page you just loaded and it appears almost instantly. That is not one optimisation doing its job. It is four, each removing a different part of the cost, and they have nothing to do with each other.

Loading the Internet Simulator simulation…

Four savings, four mechanisms

StageWhat is reusedWhere it is remembered
DNSThe address for the nameThe resolver, for the record TTL
TCPThe open connection itselfThe browser, while it stays open
TLSA session ticketThe client, until it expires
HTTPThe response bodyThe cache, per RFC 9111

Notice how differently they fail. A DNS entry expires on a timer nobody consults; a connection is closed by whichever side loses patience first; a TLS ticket is a bearer credential with a lifetime; and an HTTP response can be stale and still useful, which is a state the other three have no equivalent of.

Check yourself
On the reload above, the document came back as a 304 with no body. What did that save, and what did it not?

Fresh, stale, and the four assets that were never asked for

Four of the page's assets produced no network activity at all. Their cached copies were still fresh — the time since they were stored is less than the lifetime the server gave them — so the browser used them without asking anyone.

That is the strongest form of caching, and it is qualitatively different from the 304: a fresh hit is not a faster request, it is no request. It also explains why cache lifetimes are a design decision rather than a performance knob. A long lifetime means you cannot change the file; the usual answer is to change its name instead, and put a hash in it.

Predict what happens next
A stylesheet is served with a one-year max-age. You deploy a fix to it. What do returning visitors see?

Key takeaways

  • “Cached” is four unrelated mechanisms — a DNS entry, an open connection, a TLS ticket, and an HTTP response — each saving a different stage.
  • A fresh cache hit is not a faster request; it is no request, and no server is involved at all.
  • A 304 is a real round trip that saves only the body. That is still usually a very good trade.
  • Staleness is an HTTP idea. The other three mechanisms have no equivalent of “out of date but still useful”.
  • A long cache lifetime is unrecallable, which is why immutable assets get content-hashed URLs and the HTML that points at them does not.

Take it further