You fix a layout bug, deploy, refresh, and it's perfect. Ten minutes later the client sends a screenshot of the old, broken version. You ask them to clear their cache, it works, and everyone moves on. Until the next deploy.
"Clear your cache" is not a fix. It's a sign that the caching headers on the site were never designed, only inherited from a default somewhere. HTTP caching is one of the best performance tools available, and one of the most common reasons a correct deploy looks broken. The difference between the two is a handful of headers, and you can read all of them from a terminal.
Step 1: look at what the server actually sends
Before changing anything, check what's there:
$ curl -sI https://example.com/assets/style.css HTTP/2 200 content-type: text/css cache-control: max-age=31536000 last-modified: Tue, 03 Nov 2026 10:12:44 GMT etag: "6537-61a2b9c4d1e80" content-length: 25911 This is the most common misconfiguration in the wild, and it explains the screenshot. max-age=31536000 tells every browser it may reuse this file for one year without asking the server again. The filename is style.css, which never changes between deploys. So a visitor who loaded the page last week has a cached style.css that the browser considers perfectly fresh, and it won't even make a request for the new one.
Long cache lifetimes are good. Long cache lifetimes on files whose names don't change are the bug.
The two strategies that actually work
Almost every correct setup is a combination of two rules:
- Files with a content hash in the name are cached forever.
- Files without a hash, including the HTML, are always revalidated.
Modern build tools already produce hashed filenames:
dist/index.html 0.61 kB dist/assets/index-4f8c2b1a.css 24.18 kB dist/assets/index-b71e93d0.js 88.42 kB When the CSS changes, the hash changes, so the HTML references a URL that has never been cached anywhere. The old file can stay in caches for a year without harming anyone, because nothing points to it anymore. For those files, the right header is:
cache-control: public, max-age=31536000, immutable immutable tells the browser not to revalidate even when the user explicitly reloads the page, which removes a wave of pointless requests on every refresh.
The HTML is different. It's the file that contains the references to the hashed assets, so it must never be stale:
cache-control: no-cache no-cache doesn't mean what it sounds like
This is the most misunderstood header in web development. no-cache does not mean "don't cache". It means "you can store it, but you must check with the server before using it". The header that means "never store this at all" is no-store, and it's meant for sensitive responses, not for regular pages.
With no-cache and an ETag, revalidation is cheap. The browser sends the tag it already has, and if nothing changed, the server answers with an empty body:
$ curl -sI https://example.com/ -H 'If-None-Match: "a1b2c3d4"' HTTP/2 304 etag: "a1b2c3d4" cache-control: no-cache A 304 Not Modified costs a round trip but almost no data. The page is still served from cache, and it's guaranteed to be current.
Step 2: read the Network panel correctly
In DevTools, the Network tab tells you exactly where each file came from, in the Size column:
Name Status Size example.com 304 (headers only) index-4f8c2b1a.css 200 (memory cache) index-b71e93d0.js 200 (disk cache) logo.svg 200 (disk cache) api/products 200 14.2 kB (memory cache) and (disk cache) mean no network request happened at all: the browser decided the cached copy was fresh. 304 means a request happened, the server confirmed the copy was still valid. A real size means the full file was downloaded.
One trap: Disable cache at the top of the Network panel is ticked by default in many developers' setups. It's useful while working, and it's also the reason you never see the bug your client sees. Untick it, do a normal navigation instead of a hard reload, and look at the page the way a returning visitor does.
Step 3: don't forget the CDN in the middle
If the site sits behind a CDN, there are two caches with independent rules: the CDN's and the browser's. The response headers usually tell you what the CDN did:
$ curl -sI https://example.com/assets/index-4f8c2b1a.css HTTP/2 200 cache-control: public, max-age=31536000, immutable age: 86113 cf-cache-status: HIT cf-cache-status: HIT (on Cloudflare; other CDNs use headers like x-cache) means the CDN served the file without contacting your server. age is how many seconds it has been sitting in that cache.
When you need the CDN and the browser to behave differently, s-maxage applies only to shared caches like CDNs, while max-age applies to the browser:
cache-control: public, max-age=0, s-maxage=600, stale-while-revalidate=60 This lets the CDN serve a page for ten minutes, and keep serving the slightly older copy for another minute while it fetches a fresh one in the background, while the browser always revalidates. It's a good pattern for HTML on content sites, where a ten-minute delay on a new article is acceptable and server load matters. After a deploy that must be visible immediately, purge the CDN explicitly instead of waiting for the timer.
The Vary header can quietly kill your cache
Vary tells caches which request headers change the response. Vary: Accept-Encoding is normal and harmless: the compressed and uncompressed versions are stored separately. But some setups send this:
vary: User-Agent, Cookie Every distinct browser version, and every distinct cookie string, now creates a separate cache entry. With analytics cookies on every visit, that effectively means every visitor gets their own copy, and the CDN hit rate collapses. If you see a CDN that almost never reports HIT on static files, check Vary first.
A configuration that covers most sites
Translated into an Nginx example, the whole strategy fits in a few lines:
# hashed build assets: cache forever location ~* /assets/.*-[0-9a-f]{8}\.(css|js|woff2|svg|png|jpg|webp|avif)$ { add_header Cache-Control "public, max-age=31536000, immutable"; } # everything else, HTML included: always revalidate location / { add_header Cache-Control "no-cache"; } And the verification is the same curl command you started with:
$ curl -sI https://example.com/ | grep -i cache-control cache-control: no-cache $ curl -sI https://example.com/assets/index-4f8c2b1a.css | grep -i cache-control cache-control: public, max-age=31536000, immutable What about files you can't rename?
Some files keep a fixed URL by necessity: a favicon referenced by an old email template, a PDF linked from printed material, a logo embedded by partners. For those, a fixed max-age of a year is a trap. Pick a short lifetime that matches how often the file realistically changes, a day or a week, and rely on ETag revalidation after that. Slightly more requests in exchange for never being stuck with the old file.
The same goes for images uploaded through an admin panel and served at a stable URL. If editors replace an image without changing its name, a long cache means visitors keep seeing the old one. Either make the upload process generate a new filename, or keep the lifetime short.
The third cache nobody checks: service workers
If the site has ever registered a service worker, there's a third cache that ignores everything above. A service worker sits between the page and the network and can answer requests from its own storage, whatever your Cache-Control headers say. A badly written one that caches the HTML "for offline use" will keep serving the old page indefinitely, and no amount of header tuning will fix it.
Check from the console whether one is active:
> (await navigator.serviceWorker.getRegistrations()).map(r => r.scope) ['https://example.com/'] An empty array means there's no service worker and you can stop worrying. A scope means you need to look at what it caches. In DevTools, Application → Service workers shows its status and lets you tick Update on reload while debugging, and Application → Cache storage lists exactly which URLs it's holding.
The rule is the same as for HTTP caches: the HTML should always go to the network first, falling back to the cache only when offline, while hashed assets can be served from the cache directly. If a service worker was added years ago by a plugin or a template and nobody remembers why, the safest move is often to ship a version that unregisters itself and clears its caches.
The short version
Hash the files that change, cache them forever with immutable. Revalidate the HTML with no-cache and let ETag keep it cheap. Check the CDN with curl, not with a browser that has DevTools caching disabled. And the next time someone says "it works for me", open the Size column before blaming the client's browser: the answer is almost always in the headers you sent.
Written by Sara Casciaro, founder of Sabriel Agency, digital studio in Ugento (LE), Italy.

