summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-11-28 16:54:41 -0500
committerOwen Jacobson <owen@grimoire.ca>2025-11-28 16:54:41 -0500
commit357cf6e7306d9090194c3304612a021b6e9e9df0 (patch)
tree4471ffec686bf3990f5eca8f57cc82c625f0d430
parent5b3ae24fa19989f8a8bbaadaaaedec11d85dee13 (diff)
Update service workers while the application is open.
The default behaviour of a service worker is to check for updates any time the site associated with the worker is visited, but to only activate the new worker once no clients are open for that site. That effectively means that you need to open the site, close the site, and then open the site again to use new service worker capabilities, which is counterintuitive at best. I believe that the spec works this way for good reasons: probably because it means that the running service worker never changes out from underneath of a page while it's open, and only changes _between_ visits to a site. That's a good default. However, it does make testing service worker changes more difficult, as you need to restart the client application twice to see the results (or, at least, restart it once and then exit it). Since most of what we intend to use a service worker for mediates live app behaviour, it will be convenient to see those effects immediately when the service worker changes.
-rw-r--r--ui/service-worker.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/ui/service-worker.js b/ui/service-worker.js
index 2917ae7..446fbc8 100644
--- a/ui/service-worker.js
+++ b/ui/service-worker.js
@@ -3,6 +3,14 @@
/// <reference lib="esnext" />
/// <reference lib="webworker" />
+self.addEventListener('install', (event) => {
+ self.skipWaiting();
+});
+
+self.addEventListener('activate', (event) => {
+ event.waitUntil(self.clients.claim());
+});
+
self.addEventListener('push', (event) => {
event.waitUntil(
self.registration.showNotification('Test notification', {