This content originally appeared on foobartel.com :: All Posts and was authored by foobartel.com :: All Posts
After some time, I eventually managed to unregister my service worker on this site, because I kept on running into fetch
issues with Kirby’s panel API. I could not figure out what the exact issue was, so for now there won’t be any offline functionality anymore, but the panel will be working without problems for me again.
This article and this one helped me fix it, after I didn't manage to get it done at first try a few weeks ago. The final code block looks like this and went into the the footer of my site, instead of the registration of the same. The stumbling block for me was how to get to the registration of the current service worker, which navigator.serviceWorker.getRegistrations()
returns. The script now unregisters the existing service worker from every visitor who had it previously installed, once they visit this site again.
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().
then( function(registrations) {
for(let registration of registrations) {
registration.unregister();
}
})
}
Sometimes it’s a good idea to put things aside when you can’t get it done and revisit them later. Most of the time, the second attempt works much better and faster for me, since in the meantime the unconscious has pretty much done all the heavy lifting 😄
This content originally appeared on foobartel.com :: All Posts and was authored by foobartel.com :: All Posts
foobartel.com :: All Posts | Sciencx (2021-12-07T23:00:00+00:00) Unregistering a Service Worker. Retrieved from https://www.scien.cx/2021/12/07/unregistering-a-service-worker/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.