1

Last year we put online a website using Gatsby that made use of a service worker (SW) for caching files. A month ago, we put online a complete rework of this website, using a completely different tech stack (ie: not using Gatsby and SW anymore). The new version runs on Webflow now.

My problem is that the previous service worker is still installed on our customers browsers. Any previous visitor is seeing the old version of the website because the old SW cached everything.

I have no way of pushing another JS script to unregister the SW because all the JS files are cached by this same SW! This old version of the website seems to run completely offline now and I don't see a way of removing this old SW and the associated cache (without asking for my customers to manually remove the SW themselves of course).

Does anyone have any idea :D

EDIT with recent observations:

The solution is certainly to provide a new sw.js file. The easy way would have been to have Webflow (where the new website is hosted) serve a new sw.js file. Unfortunately, it does not seem to be possible (see here). But I could 301 Redirect to a different location of the sw.js file. Unfortunately (again), browsers don't accept redirect when loading a new service worker.

So I am still stuck there.

Simon
  • 591
  • 1
  • 4
  • 4
  • Does [this](https://www.gatsbyjs.com/docs/how-to/performance/add-offline-support-with-a-service-worker/#removing-the-service-worker) answer your question? Gen up the old SW and remove it. While forcing a redirect to the new SW. – Randy Casburn Feb 01 '21 at 16:56
  • 1
    The ideas at https://stackoverflow.com/questions/33986976/how-can-i-remove-a-buggy-service-worker-or-implement-a-kill-switch apply. The fact that you used Gatsby for the initial site doesn't change the approach. – Jeff Posnick Feb 01 '21 at 18:17
  • Problem is (I found out only recently) that you can't update a SW with a 301 Redirect. The browser considers it not valid and refuses to download the new SW. – Simon Feb 02 '21 at 12:54
  • I know you cannot edit sw.js, but for those who can see: https://github.com/NekR/self-destroying-sw – BorisS Jul 01 '21 at 16:41

0 Answers0