Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Service worker caching old pages with old tracking tags: fix

TRK-404Low impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

A service worker is a JavaScript file that a browser installs for your site. It sits between the page and the network and can reply to requests from a local cache. It is used by progressive web apps (PWAs), some headless builds and some WordPress or Shopify caching and offline plugins.

The problem starts when the worker caches your HTML pages. Those pages contain your tracking snippets, such as the GA4 or Google Tag Manager (GTM) code, the Meta pixel or a conversion event. If you change or fix the snippet on the server, returning visitors can still be served the saved page with the old code.

Why it costs you leads or sales

Conversions fire from the page the visitor actually sees. If that page is a stale copy, you can lose page views, form submits or purchases for the people who see it, while new visitors look fine. The gap is hard to spot because the numbers drop only for repeat visitors.

Ad platforms then get fewer conversion signals from your best audience: returning visitors who are close to buying. Reports show a quiet dip after a release, and the team may blame the change that was meant to fix tracking.

How a stale cache hides a tracking fix
  1. You fix the tagNew snippet is live on the server
  2. Service worker answersServes cached HTML from last visit
  3. Old tags runWrong ID or no snippet
  4. Conversion reportedNever reaches GA4 or ad platform

You deploy new tags, but returning visitors still get the saved page.

Conversions recorded after a tag fixExample numbers
Conversions recorded after a tag fix (example)New visitors: 40 conversions per day; Returning, stale cache: 5 conversions per day; Returning, fresh cache: 38 conversions per day0153140538New visitorsReturning, stale cacheReturning, fresh cacheconversions per day

Example: new visitors record the fix straight away, while returning visitors on a stale cache still miss conversions.

How to check if your site has it

Check for a service worker serving old pages
  1. Look for a registered worker

    In Chrome, open DevTools, go to Application, then Service workers. If a script is listed for your domain, the site uses one.

  2. Inspect the cache

    Under Application, open Cache storage. Open each cache and look for HTML URLs such as your home page or landing pages.

  3. Compare cached and live HTML

    Click a cached HTML entry and check its Response tab for your tracking snippet and IDs. Compare it with View Source on a private window.

  4. Test as a returning visitor

    Load the page, deploy a visible change, then reload in the same normal window. If you still see the old version, the worker is serving a stale copy.

  5. Check what the Network tab says

    Reload with the Network tab open. A request marked 'from ServiceWorker' in the Size column was not fetched fresh.

How to fix it

The goal is that HTML always comes from the network when online, the cache name changes with each release, and the new worker takes over quickly. Which file you edit depends on how the worker is built.

Fix by platform
  1. Use network-first for HTML

    In your service worker's fetch handler, send navigation requests to the network first and fall back to the cache only when offline. See the snippet below.

  2. Version the cache

    Change the cache name each release and delete older caches in the activate event.

  3. Activate the new worker

    Call self.skipWaiting() on install and clients.claim() on activate so open tabs stop using the old worker.

  4. Serve the worker file uncached

    Send Cache-Control: no-cache for the service worker file itself so browsers check for updates.

Service worker: network-first for pages, versioned cachejavascript
const CACHE = 'site-v2'; // change on every release

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) => {
  if (event.request.mode === 'navigate') {
    event.respondWith(
      fetch(event.request).catch(() => caches.match(event.request))
    );
  }
});
Self-removing service workerjavascript
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())
  );
});

How to confirm it's fixed

Confirm returning visitors get fresh tags
  1. Visit with the old worker

    Use a normal browser profile that loaded the site before the fix.

  2. Reload twice

    The first load fetches the new worker. After the second, check Application, Service workers, and confirm the new script is active.

  3. Check the cache

    Confirm old cache names are gone and cached HTML, if any, contains the right snippet.

  4. Fire a test conversion

    Complete a test form or action and confirm the event in GA4 DebugView or your ad platform's test tool.

Cache behaviour before and after

Before

  • HTML saved in a fixed cache name
  • Returning visitors get the old page
  • Old or missing tags run

After

  • HTML fetched from the network first
  • Cache name changes each release
  • New worker active on next visit

How to prevent it happening again

Release checklist for sites with a service worker
  • Never cache HTML cache-first; use network-first or stale-while-revalidate with care.
  • Change the cache version on every deploy that touches tags.
  • Serve the service worker file with Cache-Control: no-cache.
  • Delete old caches in the activate event.
  • After a tracking change, test in a normal profile that visited before.
  • Keep a note of which plugin or build step generates the worker.

How FunnelGuard handles this

FunnelGuard does not check for this yet. It is a possible future check. A stale service worker cache lives in each returning visitor's browser, and FunnelGuard's robot visitor normally arrives fresh.

What FunnelGuard does check nearby: it runs your real customer journeys on a schedule, and confirms the tracking hits sent to GA4, Google Ads, Meta and other platforms, and that test leads reach your inbox and CRM. If a bad cache or release leaves tags missing on a fresh visit, a failing journey can show it, with a screenshot and a likely cause.

To watch for the stale cache yourself, add the checks above to your release routine and compare daily conversion counts for returning and new users in GA4 after each deploy. A free FunnelGuard plan (1 site, 2 journeys, daily checks) can cover the basics of your key journeys.

Questions people ask

Why are my tracking tags not updating after I changed them?

A service worker may be serving a saved copy of your page to returning visitors. Open DevTools, then Application, then Service workers and Cache storage to see if one exists. If cached HTML has the old snippet, switch HTML to network-first and publish a new worker version.

Can a service worker cache Google Tag Manager?

Yes, if the worker caches HTML or script requests. A cached page can point to an old container or have no snippet. Changes published inside GTM usually still load, because the container script is fetched separately, unless the worker also caches it.

How do I clear a service worker cache?

In Chrome, open DevTools, go to Application, then Storage, and click Clear site data, or unregister the worker under Service workers. This only fixes your browser. For visitors, ship a new worker that deletes old caches in its activate event.

How do I force a new service worker to take over?

Call self.skipWaiting() in the install event and clients.claim() in the activate event. Also change the cache name on each release and serve the worker file with Cache-Control: no-cache so browsers look for updates.

Should a service worker cache HTML pages?

Usually not cache-first for pages that hold tracking code. Use network-first, falling back to the cache only when the visitor is offline. That keeps tags current while still giving a basic offline page.

How do I remove a service worker I no longer need?

Do not just delete the file or the registration code, because browsers keep the installed worker. Serve a replacement worker that deletes its caches and calls registration.unregister(), and keep it live for some time.

Does FunnelGuard detect a stale service worker cache?

No, not yet. It is a possible future check. FunnelGuard does run your real journeys on a schedule and checks tracking hits, so missing tags on a fresh visit can show up as a failing journey.

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.