0

I launched an upgrade of our popular job board as a PWA using code from the Firebase Friendlypix-web demo. My app is very different from that demo but some of the code I didn't change: the service worker. And I think that my service worker has gone rogue...

I changed the DNS back to our old website a few days later but I seem to have lost control of the website for thousands of users who visited during that brief period last month.

A hard refresh is not enough to remove the website between browser restarts, on Chrome at least. I eventually figured out how to unregister the service worker using chrome://serviceworker-internals/.

The codebase I used includes a workbox-sw.js with following code:

workbox.routing.registerRoute(
  /\.(?:png|gif|jpg|jpeg|svg)$/,
  workbox.strategies.cacheFirst({
    cacheName: 'images',
    plugins: [
      new workbox.expiration.Plugin({
        maxEntries: 60,
        maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
      }),
    ],
  }),
);

// Routes for all dynamic HTML pages.
workbox.routing.registerRoute(
  // Cache HTML files
  /[^\.]*/,
  // Use cache but update in the background ASAP
  workbox.strategies.staleWhileRevalidate({
    // Use a custom cache name
    cacheName: 'html-cache',
  })
); 

I don't understand if that is related to my problem.

What do I need to know if I want to relaunch such a PWA and retain the ability to update it?

Ken
  • 212
  • 3
  • 13
  • 1
    Take a look at https://stackoverflow.com/questions/33986976/how-can-i-remove-a-buggy-service-worker-or-implement-a-kill-switch — the guidance there, about re-deploying a no-op service worker, applies. – Jeff Posnick Jun 09 '20 at 19:11
  • Thank you @JeffPosnick for this very pertinent answer! I have already deployed a no-op worker and the site is alive again! It looks as if the buggy version is cached with some ISPs or corporate proxies, as I continue to get first-time visits from new users despite the DNS change. That's weird... Can I expect the situation to resolve within 24 hours, as the new version uses skipWaiting(), or have I lost these users forever...? – Ken Jun 10 '20 at 10:31
  • 1
    If your old SW is being aggressively cached by proxies, then there's no guarantees as to when the kill switch SW will be at 100%. The SW update flow ensures that the local HTTP cache is bypassed when checking for an update, but a proxy server that ignores Cache-Control headers could still get in the way. – Jeff Posnick Jun 10 '20 at 14:24
  • @JeffPosnick I think I figured it out. With the DNS now pointing to a site that doesn't have a service worker, clients were unable to escape from the PWA site. I added a workbox-sw.js to that conventional site and brought my users home. – Ken Jun 26 '20 at 14:03

0 Answers0