Engineering

Cache Policy Is a Design Decision

Immutable, revalidate, or no-store. Choosing wrong is how you ship a 200 for a URL that should not exist.

2 min readPublished July 15, 2026
Share on X

There are three cache headers that matter for a static site, and the default choice between them — which you get by writing nothing — is usually wrong in both directions at once.

Immutable, for anything content-hashed

If a filename contains a hash of its contents, it can never change. That is not a guess, it is a guarantee: change the file and the hash changes and the URL changes with it.

app.use("/assets/*", serveStatic({
  root: "./dist",
  onFound: (_path, c) => {
    c.header("Cache-Control", "public, max-age=31536000, immutable");
  },
}));

One year, marked immutable. A returning visitor with a warm cache never asks again, which is the entire point: the request does not happen, so there is no latency and no origin cost.

Revalidate, for names that do not change

Covers live at a stable path because the post references them by name. They change when the art changes, which is rare but real. Caching them for a week means a fix is live within a week without touching anybody's HTML.

app.use("/covers/*", serveStatic({
  root: "./dist",
  onFound: (_path, c) => {
    c.header("Cache-Control", "public, max-age=604800");
  },
}));

no-store, for anything that should not be cached

The 404 document is the case people get wrong. It is served for every unmatched URL, and it is specific to a request that should never have been made. Caching it means a later visitor gets a cached miss.

The more important half is the status code. A not-found page served with a 200 tells a crawler the URL exists and has unique content — the worst possible outcome, because it is indistinguishable from a real page.

Correct status, wrong body is still a soft 404. So is wrong body with a correct status.

Three rules I now follow

  • Hash in the filename or the content is frozen. No exceptions to the first rule.
  • Stable filename means you need an invalidation story. Pick the TTL before you pick the name.
  • Anything served for a failed request gets `no-store` and a real status code, every time.
  • Caching
  • Performance
  • HTTP
KI

Kadirul IslamVerified author

Founder, A.K Solution

Follow on X

Founder of A.K Solution. Full-stack engineer building AI agent tools like KiCode, JSON form engines like ki-forms, and high-scale SEO systems. Obsessed with shipping fast, zero-bloat software that lasts.

More from Kadirul Islam

Delete the Framework From Your Blog

A blog is the one project where the runtime is pure overhead. Here is the argument, and the build that settles it.

2 min readStatic Sites

The CSS Bug That Silently Deleted a Design System

One attribute selector outranked every component class in the build. Nothing threw, nothing warned, and the page just looked wrong.

2 min readCSS

The Router I Did Not Install

Two routes do not need a routing library. They need about forty lines and a hydration contract you can state in one sentence.

3 min readReact

Prerender Everything and Ship a Static Site

If two visitors receive identical bytes, a server runtime is a tax you agreed to pay for nothing.

2 min readWeb Development