Is it possible for a service worker to permanently violate a website?

Imagine that you are executing a service worker who implements the offline-first strategy (a typical use case for service workers), and you deploy it but it has an error. An error means that it never checks the source server for updates, even by itself. Therefore, after a service worker is registered for this customer on his first visit, that customer will never see the update on this website again (unless the user manually cancels the service employee’s account using chrome://serviceworker-internals/ or something else). In other words, the site is broken forever for these users.

Is the above scenario possible? If so, is there a strategy to make sure this never happens?

+5
source share
2 answers

TL DR

There will be no perma rewind, you can always update your worker and fix the caching problem you made.

But there will be chances that something will never be updated if you forget to update your cache and use it correctly. (regarding the first point you can always fix this, do not lure perma)


LONG answer

As far as I know, there are some bad scenarios when you rely too much on the use of caches, BUT , it depends on the strategy, this is unlikely for the strategy "offline first", but others.

As if you had prior knowledge of Service Worker, you will find out that we can do some kind of network balancing for a specific browser request. For sorting, we can do something like:

Offline first

First online

Quick

Internet only

Offline only

etc .. (names are for illustration only)

And if you are going to use something like Offline only for certain files / places, you may find that places / files will never be updated.

So, the answer is this: there is always a chance that something went wrong, but because you are worried, this probably does not always happen. If you want to prevent it , be sure to always update the contents of the cache for Offline first when it is available.


To add an @anshulix answer, I'm not sure if this was behavior from an old service employee. But for my recent experiment, no matter what you do, if the service worker is ONCE INSTALLED, he will always try to update himself ONLY every time you download the site.

With this, you can always fix your mistakes immediately, and the end user will receive a correction after loading the first site or loading the second site.

+3
source

haha, no, this does not happen, the service-to-service file has a periodic update of 24 hours, even if the first official is wrong, he will always check on the server if there are any changes and updates.

mdn

+1
source

All Articles