Skip to content
All notes
DevelopmentNov 17, 20265 min read

Why visitors can see old website content after a deployment

Browsers, CDNs and service workers can keep an old copy of your site. Learn where stale content hides and how to make each deployment reach visitors.

The short version

  • Old content usually comes from a stored copy in the browser, a CDN or a service worker, and it stays in use until it expires or its address changes.
  • Giving changed files a new address on every deployment, and making caches check your HTML page, lets new content reach visitors.
  • A service worker waits before it takes over and does not delete old caches by itself, so it needs its own update plan.

You publish a website update. You open the page on your laptop and the new design looks right. Then a customer sends you a screenshot, and it shows yesterday’s version.

Your server holds the new files, so the old copy must be coming from somewhere else. Where?

The old copy usually comes from a stored copy that sits between your server and the visitor. It can be in the visitor’s browser, in a shared cache such as a content delivery network (CDN), or in a service worker. A stored copy stays in use until it expires or its address changes. The fix is to give changed files a new address on every deployment and to make caches check your HTML page before they reuse it. How much this matters depends on your headers, your CDN settings and whether your site has a service worker.

Three places an old copy can hide

Browser and shared caches can keep resources that visitors already downloaded. MDN describes two kinds. A private cache belongs to one client, usually the browser. A shared cache can serve many visitors. It includes proxy caches, which you do not control, and managed caches such as CDNs, reverse proxies and service workers, which you configure.

The web.dev guidance describes the order of checks. A service worker answers first, if the site has one and it handles the request. The browser’s HTTP cache comes next. Only then does the request travel to the network, which can include a CDN before your own server.

Where the copy sits Who controls it What keeps it in use
Visitor’s browser The visitor, guided by your headers The freshness time in your Cache-Control header
CDN or other shared cache You, through its settings Your headers, or its own default time
Service worker Your site code The caching strategy in that code

How long a stored copy counts as fresh

A cache treats a response as fresh until its age passes the max-age value in the Cache-Control header. After that, it is stale. A stale copy is not thrown away. The cache asks the server whether it changed, and the server answers 304 if it did not.

MDN gives a worked example. A file is sent with a max-age of one week, which is 604,800 seconds. A shared cache has held it for one day, so it reports an Age of 86,400 seconds. The visitor’s browser then treats the file as fresh for another 518,400 seconds, which is six days. A change on your server does not reach a browser that treats its copy as fresh.

A cached file stays in use until it expires or its address changes.

One more detail matters. If a response has no Cache-Control header, browsers may still store it and reuse it. MDN says the specification suggests about 10% of the time since the file was last modified. A file last changed 30 days ago could be reused for around 3 days, with no header at all. Set an explicit header on every response, as MDN recommends.

Fix 1: give changed files a new address

You cannot change how long a visitor already holds a file. You can make the new file a different file. MDN recommends putting a version or a content hash in the file name, such as bundle.v123.js. When the content changes, the address changes, so the old copy is never asked for again. That also makes a very long lifetime safe. MDN recommends this header for such files, when you never personalise them with an Authorization header:

Cache-Control: public, max-age=31536000, immutable

One year is 31,536,000 seconds. The immutable keyword stops browsers from asking the server again when a visitor reloads.

Your HTML page is different, because visitors need a stable address for it. MDN and web.dev both say it needs revalidation, so use this header:

Cache-Control: no-cache

Despite the name, no-cache lets caches store the page. It requires them to check with the server first. MDN recommends sending an ETag or Last-Modified header as well, so an unchanged page returns a short 304 reply.

Fix 2: check what your CDN does with your headers

Providers differ here, so read the documentation of your own. Cloudflare’s documentation, updated in September 2026, gives one example. It decides what to cache by file extension, and it does not cache HTML or JSON by default. It follows your Cache-Control header. It will not cache a response marked private, no-store, no-cache or max-age=0, or one that sets a cookie. Without cache headers, it keeps a successful response for 120 minutes by default, so a changed file with the same address can be served from the edge for up to two hours. Check how your CDN clears stored copies of a file.

When a service worker keeps serving the old file

A service worker is a script that sits between your page and the network. It can answer requests from its own cache.

Chrome’s Workbox documentation says a cache-first strategy keeps serving the first stored copy when the file name does not change. It recommends versioned file names, a network-first or stale-while-revalidate strategy for such files, or a precache list that the tooling keeps current.

A new service worker version does not take over at once. According to MDN, it installs in the background and then waits. It activates only when no open page uses the old version. A plain refresh may not be enough, because the old page overlaps with the new one. MDN also says the old caches stay until your own code deletes them, usually in the activate step. Installing a new service worker does not clean them up.

What to check after your next deployment

The customer’s screenshot came from a stored copy, and now you can name the three places it could sit.

Open your homepage in the browser’s developer tools with the Network tab showing. Click the HTML file and read its Cache-Control, ETag and Age headers. Age shows how long a shared cache has held that copy. Then check that the script and style files have names that change when their content changes. If your site registers a service worker, read its caching strategy next.

Do this today

0 of 5 done