From fb6a1da62a40fc81ba83e679cc6e695652263fd9 Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Sun, 7 Jul 2024 17:33:20 +0200 Subject: [PATCH] update service worker --- static/dist/support.js | 7 ++++++- static/dist/sw.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/static/dist/support.js b/static/dist/support.js index 2545bbf..2a9bce5 100644 --- a/static/dist/support.js +++ b/static/dist/support.js @@ -14,9 +14,14 @@ document.querySelector("main").addEventListener("scroll", () => { async function registerServiceWorker() { if ("serviceWorker" in navigator) { try { - await navigator.serviceWorker.register("/sw.js", { + const registration = await navigator.serviceWorker.register("/sw.js", { scope: "/", }); + if (registration.installing) { + setTimeout(() => window.location.reload(), 500); + } else if (registration.active) { + console.log("Service worker active"); + } } catch (error) { console.error(`Could not install service worker: ${error}`); } diff --git a/static/dist/sw.js b/static/dist/sw.js index 5768bc6..dd9bb4e 100644 --- a/static/dist/sw.js +++ b/static/dist/sw.js @@ -35,4 +35,4 @@ async function getFromCache(event) { self.addEventListener("fetch", (event) => { handleRequest(event); -}); \ No newline at end of file +});