How to Get Caching Strategy Right
Deciding what is stored, where, and for how long — in the browser, at a CDN edge, and inside the application — so repeated work is not repeated.
Where most projects go wrong
The usual mistakes:
- Long cache lifetimes on URLs whose content changes
- Caching at the edge without checking for personalised content in the response
- Clearing the whole cache as the routine answer to any problem
- Multiple caching layers that nobody can reason about together
What good looks like instead
- Fingerprint static assets and cache them for a long time
- Keep HTML short-lived or revalidated so content changes appear
- Vary correctly on anything that changes the response, including compression and language
- Never cache a response that contains data belonging to one user
- Decide how each cache is cleared before you turn it on
Why it matters
Caching is the cheapest performance improvement available and the most dangerous when it is wrong, because a badly cached page serves one person's data to another.
The specs that matter
| Measure | Figure |
|---|---|
| Browser caching header | Cache-Control, with max-age and immutable for fingerprinted assets |
| Revalidation | ETag or Last-Modified, answered with 304 Not Modified |
| Fingerprinted asset practice | long max-age, because the filename changes when the content does |
| HTML practice | short or no-cache, because the URL does not change when the content does |
| The hard part | invalidation, not storage |
Knowing when to hand it over
Tip: Bring in help when stale content keeps reappearing after a publish, when a cache has leaked personalised data even once, or when several caching layers interact in ways nobody on the team can explain.
Where this comes from
- MDN Web Docs — HTTP caching
- Cloudflare Learning Center — What is caching
- RFC Editor — RFC 9111, HTTP Caching
The figures and practices above come from the sources listed.
Working on something like this?
We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.
Where to go next
Spotted something wrong? Report an error on this page. We correct on the page and say what changed.