Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Service worker serving a stale cached site: how to fix it

PRF-130Medium impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

A service worker is a JavaScript file that your site registers in the visitor's browser. It sits between the page and the network and can reply to requests from a local cache. Progressive web apps, some themes and some plugins use it to make sites load faster or work offline.

The problem starts when the worker holds on to old files. It may serve an old HTML page that points to scripts you have since deleted. It may serve an old form script, an old checkout page or an old tracking tag. You deploy a fix, you see it working, and a returning visitor still sees the broken version.

Common causes: a cache-first rule applied to HTML pages, a cache name that never changes, no cleanup of old caches, or the sw.js file itself being cached by the browser or CDN so the update is never found.

Why it costs you leads or sales

Stale caches are hard to notice because you and your developer usually see the fixed site. Returning visitors, often your warmest leads and repeat buyers, keep the old copy. They may hit a form that posts to a retired endpoint, a checkout script that no longer matches the server, or a page with an old price or offer.

Tracking can break too. An old cached page may carry an outdated tag setup, so conversions go missing from ad platforms even though the funnel looks fine to you.

How a stale service worker breaks a returning visitor's journey
  1. You deploy a fixNew HTML and scripts go live on the server
  2. Returning visitor opens pageBrowser asks the service worker first
  3. Worker serves cached copyOld HTML points to old or missing scripts
  4. Form or checkout failsScript error or old endpoint
  5. ConversionLead or sale never recorded

The worker answers from its cache, so the fixed version never reaches the browser.

Old cached page meets new server

The cached page loads, but the scripts it expects no longer match the server.

How to check if your site has it

Check for a service worker in Chrome
  1. Open DevTools Application panelCustom code

    Open your site, press F12 (Cmd+Option+I on Mac), and go to Application, then Service workers. If a worker is listed with a status like 'activated and running', your site uses one.

  2. Look for waiting workers

    A second entry marked 'waiting to activate' means a new version is downloaded but the old one is still in control. That is a classic stale cache sign.

  3. Inspect the cached files

    Under Application, then Cache storage, open each cache and check whether it holds HTML pages or old script filenames.

  4. Compare cached and live

    Tick 'Bypass for network' in the Service workers panel and reload. If the page now behaves differently or the error disappears, the worker is serving a stale copy.

  5. Test as a returning visitor

    Visit the site in a normal window before a deploy, deploy a change, then reload without clearing anything. If you still see the old version, updates are not reaching returning visitors.

  6. Check the worker file headers

    In the Network panel, select sw.js and look at Cache-Control. A long max-age on this file delays updates.

How to fix it

The right fix depends on whether you want the service worker at all. If it is not giving you a clear benefit, remove it. If you need it, change its caching rules so pages are always fresh.

Fix by platform
  1. Find what registers the worker

    Check PWA, caching and performance plugins (for example a PWA plugin or an offline mode setting). Look at the page source for navigator.serviceWorker.register.

  2. Disable or update the plugin setting

    Turn off offline or PWA mode, or switch the HTML caching strategy to network-first if the plugin offers it.

  3. Purge caches

    Clear your caching plugin and CDN caches so the changed sw.js is served fresh.

  4. Ship a cleanup worker if needed

    If visitors still hold the old worker after you remove the plugin, serve a replacement sw.js that unregisters itself (see the code below).

A safer service worker: versioned cache, network-first HTMLjavascript
const CACHE = 'site-v2025-01-15';

self.addEventListener('install', () => self.skipWaiting());

self.addEventListener('activate', (event) => {
  event.waitUntil(
    caches.keys()
      .then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
      .then(() => self.clients.claim())
  );
});

self.addEventListener('fetch', (event) => {
  const req = event.request;
  if (req.method !== 'GET') return;
  if (req.mode === 'navigate') {
    event.respondWith(
      fetch(req).catch(() => caches.match(req))
    );
    return;
  }
  event.respondWith(
    caches.match(req).then((hit) => hit || fetch(req).then((res) => {
      const copy = res.clone();
      caches.open(CACHE).then((c) => c.put(req, copy));
      return res;
    }))
  );
});
Kill switch: unregister workers and clear caches for existing visitorsjavascript
// Serve this as /sw.js to replace a bad worker:
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', (event) => {
  event.waitUntil(
    caches.keys()
      .then((keys) => Promise.all(keys.map((k) => caches.delete(k))))
      .then(() => self.registration.unregister())
      .then(() => self.clients.matchAll())
      .then((clients) => clients.forEach((c) => c.navigate(c.url)))
  );
});

// Or, from a page script:
if ('serviceWorker' in navigator) {
  navigator.serviceWorker.getRegistrations().then((regs) => regs.forEach((r) => r.unregister()));
}
Make sure sw.js is never cached for longnginx
location = /sw.js {
  add_header Cache-Control "no-cache";
}
Caching strategy before and after

Before

  • HTML cached cache-first
  • Cache name never changes
  • Old caches never deleted
  • sw.js cached for days

After

  • HTML fetched network-first
  • Cache name versioned per release
  • Old caches deleted on activate
  • sw.js served with no-cache

How to confirm it's fixed

Verify the update reaches returning visitors
  1. Load the site with the old worker

    Use a browser profile that visited before the fix and has not been cleared.

  2. Reload twice

    In DevTools, Application, Service workers, confirm the new worker becomes 'activated' and no worker is stuck 'waiting'.

  3. Check cache storage

    Only the current versioned cache should remain.

  4. Run the full journey

    Submit a test lead or reach the checkout (stop before payment) and check the Console for errors.

  5. Check sw.js headers

    Confirm Cache-Control is no-cache or a very short max-age.

How to prevent it happening again

Prevention checklist
  • Ask whether you really need a service worker for a lead or sales site
  • Never cache HTML or API responses cache-first
  • Version cache names on every deploy
  • Delete old caches in the activate event
  • Serve sw.js with Cache-Control: no-cache
  • Test every release in a profile that already has the previous version installed
  • Keep fingerprinted file names for scripts and styles
  • Add a note to your release checklist to check Application, Service workers
Example: how a stale worker unfolds
  1. Day 0

    Worker installed and caches pages cache-first

  2. Day 10

    You deploy a new form script and remove the old one

  3. Day 10

    Returning visitors still get cached HTML that loads the deleted script

  4. Day 14

    Leads from returning visitors drop, but new visitors convert normally

  5. Day 15

    You ship a versioned worker and no-cache sw.js

How FunnelGuard handles this

FunnelGuard does not check for this yet. Detecting a stale service worker is a possible future check, not something it does today.

What FunnelGuard does do is run your real journeys (lead forms, checkouts, booking and chat buttons) on a schedule from the EU or the US, check each step and the tracking hits sent to platforms such as GA4, Google Ads and Meta, and confirm test leads reach your inbox and CRM. A failure is re-checked from a second region before one alert goes out. Because a robot visitor usually starts clean, it may not hold an old worker, so it can miss a problem that only affects returning visitors.

To watch for this yourself, add the service worker check to your release routine: open the site in a browser profile that has visited before, deploy, reload, and confirm Application, Service workers shows no waiting worker. You can also try the free plan (1 site, 2 journeys, daily checks, no card) to cover the broader funnel while you do this manually.

Questions people ask

Why is my website showing an old version after I updated it?

If browser refresh and server cache purges do not help, a service worker may be answering from its own cache. Open DevTools, Application, Service workers, and tick 'Bypass for network'. If the new version appears, the worker is serving stale files.

How do I unregister a service worker?

For yourself, open DevTools, Application, Service workers and click Unregister. For all visitors, serve a replacement sw.js that deletes caches and calls self.registration.unregister(), and leave it live for a few weeks.

How do I clear a service worker cache in Chrome?

Open DevTools, go to Application, then Storage, and click 'Clear site data'. You can also open Cache storage and delete individual caches. This only fixes your own browser, not your visitors'.

Why is my service worker update stuck on 'waiting to activate'?

A new worker waits until all tabs using the old one are closed. You can call skipWaiting() in the install event to activate it immediately, but only if your pages stay compatible when the worker changes mid-session.

Can a service worker break my checkout or contact form?

Yes. If it serves cached HTML or scripts that no longer match the server, forms can post to old endpoints or throw script errors. Returning visitors are the most affected.

Should I cache HTML in a service worker?

For lead and sales funnels, serve HTML network-first, falling back to cache only when offline. Cache-first HTML is the main cause of visitors seeing outdated pages.

Why is sw.js not updating?

The file is probably cached by the browser, a CDN or a caching plugin. Serve sw.js with Cache-Control: no-cache and purge your CDN so browsers can fetch the new version.

Does FunnelGuard detect a stale service worker?

No, not yet. It is a possible future check. FunnelGuard does run your real funnel journeys on a schedule and checks steps, tracking and test leads, but you should check service worker state manually after deploys.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.