Skip to content
Small Systems Notebook

Working notes on running small web services without drama.

Cache headers that age well

Cache headers that age well
Long-lived assets, short-lived pages, and the one header that makes both safe.

The simplest cache policy that has survived several redesigns: fingerprinted assets get a year and immutable, HTML gets max-age=0, must-revalidate. Browsers then ask for pages on every visit but almost never for stylesheets or images.

The part that is easy to get wrong is the fingerprint itself. It has to change when the bytes change and only then, so it should be computed from content, not from a build number. A build that produces identical files must produce identical names.

/assets/site-3f9a1c2e.css   Cache-Control: public, max-age=31536000, immutable
/notes/                     Cache-Control: public, max-age=0, must-revalidate

#http#caching