update service worker

This commit is contained in:
marlon-erler
2024-07-07 17:33:20 +02:00
parent 7e7316dcb5
commit fb6a1da62a
2 changed files with 7 additions and 2 deletions
+6 -1
View File
@@ -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}`);
}