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?
Service worker caching strategies and use cases #It's preferable to serve the fresh content. However if the network fails or is unstable, it's acceptable to serve slightly old content. It's okay to serve cached content right away, but updated cached content should be used in the future.
Open the 'Application' tab and the 'Storage' item. Here, you'll see how much storage your service worker occupies, and you can select which data to clear for that website, for example retaining only the cookies. Note that the service worker will restart as soon as you navigate to that site again.
# Access to a JavaScript-driven caching API An indispensable aspect of service worker technology is the Cache interface, which is a caching mechanism wholly separate from the HTTP cache. The Cache interface can be accessed within the service worker scope and within the scope of the main thread.
Browser Service Worker Cache Capacity. Service workers enable web sites to work offline using the Cache API. Developers need to design the logic to manage how site assets are persisted in storage.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With