callum
callum

Reputation: 37729

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

Imagine you make service worker that implements an 'offline first' strategy (the typical use case for service workers), and you deploy it to production, but it has a bug. The bug means that it never actually checks with the origin server for updates, even to itself. So after the service worker is registered for a given client on their first visit, that client would never see any update to that website again (unless the user manually unregisters the service worker using chrome://serviceworker-internals/ or something). In other words, the site is broken forever for those users.

Is the above scenario possible? If so, is there a strategy for making sure it never happens?

Upvotes: 6

Views: 1024

Answers (2)

Linh Pham
Linh Pham

Reputation: 3025


TL;DR

There will be no perma break, you can always update your service worker and fix the caching issue you've made.

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


LONG answer

As far as I know there are some bad scenarios when you are rely too much on using caches, BUT it is depends on the strategy, it is not likely happen on "offline first" strategy but the others.

As if you have an advance knowledge about Service Worker, you will know we can do some sort of network balancing for certain request of browser. For sort we can do something like:

Offline first

Online first

Fastest

Online only

Offline only

etc.. (the names are only for illustrations)

And if you are going with something like Offline only for certain files/places, you may ended up with that places/files will never be updated.

So the answer is: there always chances that something went wrong, but for the thing you are worrying it is likely not always happen. If you want to prevent it make sure to always update the cache content for Offline first when it is available


To add up the answer of @anshulix I am not sure if that behavior was from old service worker. But for my recent experiment, regardless what you are doing, if service worker ONCE INSTALLED, it will always try to update itself ONCE every time you load the site.

With this you can always fix your mistakes right away and end-user will got the fix after first site loaded or second site loaded.

Upvotes: 4

anshulix
anshulix

Reputation: 197

haha, no it doesn't happen this way, service-worker file has a periodic update in 24 hours, even if the first service-worker was buggy, it would always check on server if there are any changes and updates.

mdn

Upvotes: 2

Related Questions