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.
This commit is contained in:
maziggy
2026-03-23 15:32:06 +01:00
parent bc37c12f90
commit 8d60c31aa7
2 changed files with 14 additions and 4 deletions
+7 -2
View File
@@ -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
View File
@@ -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', () => {