awsm.webnotes on small websites

Cache headers for files that never change

2026-02-19

There are only three caching situations on a static site, and confusing them is why sites either serve stale pages or re-download the same stylesheet forever.

Versioned assets

If the filename changes whenever the bytes change, the file is immutable. Say so, and the browser stops asking:

Cache-Control: public, max-age=31536000, immutable

HTML

HTML is the entry point and must never be served stale, but it also does not need to be re-fetched in full on every navigation. Revalidation is the right trade:

Cache-Control: no-cache

Despite the name that does not mean "do not store" — it means "store it, but check before reusing". With an ETag the check is a 304 and a few hundred bytes.

Everything else

Unversioned images, feeds, a favicon: a short max-age plus revalidation. An hour is usually right. The mistake is reaching for the immutable header here because it worked on the stylesheet — the only way to fix a wrong answer then is to rename the file.