[w3c/ServiceWorker] Why is it possible to register a service worker that you won't ever be able to remove? (#1258)

I've deployed a new version of my site (It was on Polymer, now on Vue.js) to Firebase over an existing project.

I'm using default Vue.js template with Webpack (`vue init webpack my-project`) in the new project

---

Now that I've deployed the new version, a few days after, I still see just a cached shell of previous deploy, when I open the site. I assumed that's the service worker's fault.

In order to get actual current files from Firebase I (and all the previous visitors) have to now hard refresh the site every time (`Ctrl+F5` in firefox)

## Console

Now, in browser console (network tab) I see:

[![enter image description here][1]][1]

- The service worker in red, it says: `(failed) net::ERR_INSECURE_RESPONSE` when I normally open the site (without hard refresh)

- Some of the files have size property of `(from ServiceWorker)` - these files have `cache-control:max-age=3600` but it's been more than an hour since I've deployed new version of the site. It looks like the service worker itself doesn't have any headers, maybe that's why it still keeps loading the old files a few days after the new deploy

---

I've added this code to `firebase.json`, then `npm run build` trying to remove the service worker, but I still have the issue

## Firebase.json

    {
      "hosting": {
        "public": "dist",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ],
        "headers": [
          { "source":"/service-worker.js", "headers": [{"key": "Cache-Control", "value": "no-cache"}] }
        ]
      }
    }

## Service worker code from the previous project 

I don't use any service workers on the newly deployed version. But the previous deploy registered a service worker

I was using the default sw-precache component from Polymer 1.0 framework's library that was built in the pre-configured Polymer starter kit template that I used. Service worker was generated at build time

**Bundled > service-worker.js:** [https://jsfiddle.net/uydjzw13/][2]

**Unbundled > service-worker.js:** [https://jsfiddle.net/t42fdgow/][3]
    
---

## Question:

Is there a way to remove that old service worker from all the site visitors' browsers so that they always get the newly deployed version? Maybe I can do that with Webpack or Firebase somehow?

---

Is it going to get fixed if I just delete the previously deployed version with the service worker from Firebase?

Or maybe I could deploy another version with a service worker that has the only function that deletes all previous cache and unregisters previous service worker, if that's possible? 

Or can I use something like this maybe?: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/unregister

I'm not sure how to do that correctly and not accidentally register any more service workers that I also won't be able to get rid of.

  [1]: https://i.stack.imgur.com/Q761w.png
  [2]: https://jsfiddle.net/uydjzw13/
  [3]: https://jsfiddle.net/t42fdgow/

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1258

Received on Wednesday, 10 January 2018 12:42:11 UTC