Domains, CDN & Web Delivery

Cache-Control

Definition

Cache-Control is a header sent with every response, carrying a comma-separated list of directives, and the ones that matter in practice are few. max-age gives the freshness lifetime in seconds, so max-age=31536000 means one year and max-age=0 means stale immediately. public says any cache may store it, including a shared CDN; private restricts storage to the visitor's own browser. immutable promises the file will never change at that address, which stops the browser revalidating it even on a reload. s-maxage sets a separate, usually longer, lifetime for shared caches only, so an edge node can hold something for a day while browsers hold it for five minutes. Two more are widely misunderstood — no-cache and no-store are not synonyms, and the difference between them is the subject of most caching confusion.

Why It Matters

The difference between a repeat visit costing 40 requests and costing none is one header. A typical static page with a stylesheet, two scripts, a font and a dozen images loads in perhaps 1.5 seconds cold; with those assets held for a year it loads in about 200 milliseconds, because nothing leaves the machine. Get it wrong the other way and the effects are just as large: no-store on your images means every visitor refetches every one of them on every page, which drags the cache hit ratio down to almost nothing. The costly mistake is the opposite one, though — a long max-age on a file you later need to change, at an address that stays the same, means returning visitors will not ask again for a year and there is no way to reach them.

How It Works

Each cache along the path stores the body with a timestamp and the stated lifetime, and while the file is within that lifetime it is served without any network request at all. Once it expires the cache does not simply discard it — it makes a conditional request, sending If-None-Match with the stored ETag, and an unchanged file comes back as a 304 Not Modified with no body. That is where no-cache and no-store diverge. no-cache means store the copy but revalidate before every use, so you still get 304s and save the download; no-store means keep nothing at all, discard it after use, and refetch in full every time. Use no-store only for genuinely sensitive responses. The standard split for a static site is Cache-Control: public, max-age=31536000, immutable on hashed asset filenames, and Cache-Control: no-cache on the HTML that references them.

Real-World Example

A shop uploads a static catalogue to 99helpers at merrow-goods.99helpers.site, with the pages referencing a stylesheet and product photographs. A visitor browsing eight pages downloads the shared assets once; the other seven pages arrive as markup alone, a few kilobytes each, because the images were already held locally with a long lifetime. Sensible headers are applied by 99helpers automatically rather than being something you write into a server config. The visible result is that the second page feels instant.

Common Mistakes

  • Treating no-cache and no-store as the same instruction — no-cache still keeps the copy and revalidates cheaply, while no-store throws away a perfectly good file and redownloads it in full
  • Putting a one-year max-age on HTML — the markup is the one file that must change, and visitors holding an old copy will never see a correction
  • Adding immutable to a filename without a content hash in it — you have promised something you cannot keep, and the browser will believe you
  • Setting only max-age and expecting a shared cache to behave differently from a browser — that is what s-maxage exists for, and without it both use the same number

Related Terms

Put a file online in seconds

Drop in a document, an image, a page or a whole static website and share the link — free, with no build step and no server to set up.

Host a file free →