QR Code contains TinyURL of this article.WTF is Wrong with My Service Worker?

Stylised rendering of a confused man, scratching his head

I’ve had a service worker running on this website for the past ten months or so. It maintains a cache of files in the client browser so as to enable the site to run in an offline mode as per the current PWA paradigm.

As far as I’m aware, it’s been running flawlessly since I deployed it. However, last week I noticed that all was not well. The service worker wasn’t updating the caches correctly, or at all in some cases.

I’ve spent the past three days trying to get to the bottom of the problem. So far, to no avail.

Curiously, everything works perfectly locally.

If anyone out there can work out what’s going wrong and point me towards a fix, I would appreciate it.

The service worker source code is available as a Gist.