7

From my service worker, I am saving some assets in the browser cache, as well as the service worker script itself, and it works fine so that I can see the service worker url together with all other assets in my devtools cache tab.

Now, when I go offline, my service worker listens to the fetch event and gets all assets from cache.

However, there seems to be no fetch event when the page tries to register the worker itself, therefore I'm getting the following errors in the console:

console error

console erorr

Am I missing something? After all, does it make sense to cache the service-worker script itself?

Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
VasChat
  • 73
  • 1
  • 4
  • http://stackoverflow.com/questions/39418740/service-worker-file-not-found-in-offline-mode/39419655#39419655 and http://stackoverflow.com/questions/38843970/service-worker-javascript-update-frequency-every-24-hours/38854905#38854905 both provide some relevant information. – Jeff Posnick Oct 21 '16 at 20:26
  • @JeffPosnick thanks a lot for the tip – VasChat Oct 22 '16 at 19:29
  • Note that if it were possible for a service worker to cache itself, there would be no way to ever update it! – Antimony Nov 04 '16 at 02:00

1 Answers1

9

According to the specification of the update algorithm (which is run for registering also). At the point 7.2:

Set request’s skip service worker flag and request’s redirect mode to "error".

That's mean your service worker request will never pass through the service worker. Instead, it is cached in its own cache according to its own rules. What you see as errors, are the failing attempts of the browser to get a fresh version of the service worker.

As Jeff Posnick says in one of his replies, you can safely ignore these errors.

Salva
  • 6,507
  • 1
  • 26
  • 25