Skip to content
Web Design & Development

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.

Marcus Adeyemi Technical Director 2 min read 20 views
How to Get Caching Strategy Right

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
What to do and what to avoid with caching strategy, side by side
Good practice against the usual mistakes, from the sources listed below.

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

Published figures for Caching Strategy
MeasureFigure
Browser caching headerCache-Control, with max-age and immutable for fingerprinted assets
RevalidationETag or Last-Modified, answered with 304 Not Modified
Fingerprinted asset practicelong max-age, because the filename changes when the content does
HTML practiceshort or no-cache, because the URL does not change when the content does
The hard partinvalidation, 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

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.

All services

The work behind this article, and what it costs.

Marcus Adeyemi

Builds and maintains the web work. Writes about front-end architecture, performance, accessibility and the unglamorous parts of keeping a site alive.

Keep reading

More in Web Design & Development