Browse Source

Force-clear service worker and caches on SpoolBuddy kiosk load

  Just unregistering the SW wasn't enough — the old SW still controlled
  the page for that load. Now detects if any SW exists, nukes all SWs
  and caches, then reloads once to get a clean fetch from the server.
  Subsequent loads skip this since no SW is registered.
maziggy 2 months ago
parent
commit
8d60c31aa7
2 changed files with 14 additions and 4 deletions
  1. 7 2
      frontend/index.html
  2. 7 2
      static/index.html

+ 7 - 2
frontend/index.html

@@ -32,9 +32,14 @@
     <script>
       if ('serviceWorker' in navigator) {
         if (location.pathname.startsWith('/spoolbuddy')) {
-          // Kiosk mode — unregister any existing SW to avoid stale cache
+          // Kiosk mode — nuke SW and all caches, then reload once to get clean state
           navigator.serviceWorker.getRegistrations().then((regs) => {
-            regs.forEach((r) => r.unregister());
+            if (regs.length > 0) {
+              Promise.all([
+                ...regs.map((r) => r.unregister()),
+                caches.keys().then((names) => Promise.all(names.map((n) => caches.delete(n)))),
+              ]).then(() => location.reload());
+            }
           });
         } else {
           window.addEventListener('load', () => {

+ 7 - 2
static/index.html

@@ -33,9 +33,14 @@
     <script>
       if ('serviceWorker' in navigator) {
         if (location.pathname.startsWith('/spoolbuddy')) {
-          // Kiosk mode — unregister any existing SW to avoid stale cache
+          // Kiosk mode — nuke SW and all caches, then reload once to get clean state
           navigator.serviceWorker.getRegistrations().then((regs) => {
-            regs.forEach((r) => r.unregister());
+            if (regs.length > 0) {
+              Promise.all([
+                ...regs.map((r) => r.unregister()),
+                caches.keys().then((names) => Promise.all(names.map((n) => caches.delete(n)))),
+              ]).then(() => location.reload());
+            }
           });
         } else {
           window.addEventListener('load', () => {