Coockar

Published: 1 min read

Designing CDN cache headers

How to set Cache-Control for a static site: hashed assets go immutable, HTML stays short-lived with revalidation — a two-tier baseline.

A static site lets you decide exactly what gets cached and for how long. Decline to decide, and you inherit whatever the CDN and browsers default to. A two-tier baseline turned out to be enough.

The two tiers

Assets whose filenames carry a content hash (CSS, JS, optimized images) change URL whenever they change content, so they can take the longest cache lifetime plus immutable.

/_assets/*  Cache-Control: public, max-age=31536000, immutable
/*.html     Cache-Control: public, max-age=0, must-revalidate

HTML is the opposite: the URL stays put while the content updates. Keep it short-lived and revalidated — fresh content flows immediately after a deploy, and while the ETag still matches, 304 responses keep transfer sizes down.

Where the edge cache fits

The host’s edge network may cache in a layer of its own, independent of these headers. If your platform purges the edge automatically on deploy, you can afford a longer HTML max-age; but starting from “don’t let browsers hold HTML too long” was the safe lean.

Takeaway

Hashed files forever, HTML short with revalidation. Start from those two lines and tune individual paths only where transfer volume or latency actually hurts — that ordering leaves the fewest regrets.