diff --git a/src/index.tsx b/src/index.tsx index 06cec1b4..c7f610d4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -24,7 +24,9 @@ setInitialPage(); if (SW) { if ('serviceWorker' in navigator) { - navigator.serviceWorker.register(`sw.js`) + navigator.serviceWorker.register(`sw.js`, { + scope: '.' // <--- THIS BIT IS REQUIRED + }) .then((registration) => { // eslint-disable-next-line no-console console.log('Registration successful, scope is:', registration.scope); diff --git a/src/sw.ts b/src/sw.ts index 9857f8c3..dd98b513 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -21,9 +21,29 @@ self.addEventListener('install', (event: any) => { ); }); -// self.addEventListener('activate', () => { -// console.log('activate'); -// }); +self.addEventListener("activate", (event: any) => { + async function deleteOldCaches() { + // List all caches by their names. + const names = await caches.keys(); + await Promise.all(names.map(name => { + if (name !== CACHE_NAME) { + // If a cache's name is the current name, delete it. + return caches.delete(name); + } + })); + } + + event.waitUntil(deleteOldCaches()); +}); + +window.addEventListener("online", () => { + // eslint-disable-next-line no-console + console.log("You are online!"); +}); +window.addEventListener("offline",() => { + // eslint-disable-next-line no-console + console.log("Network connection lost!"); +}); const MAX_AGE = 1000 * 60 * 10; // 10 minutes. diff --git a/static/manifest.json b/static/manifest.json index bd266d4e..0ad51ae2 100644 --- a/static/manifest.json +++ b/static/manifest.json @@ -1,10 +1,10 @@ { - "name": "Medžuslovjansky slovnik", - "short_name": "Medžuslovjansky slovnik", + "name": "MS TEST", + "short_name": "MS TEST", "description": "Word dictionary for interslavic language", "lang": "en", "dir": "ltr", - "scope": "https://interslavic-dictionary.com/", + "scope": "https://pr-342.interslavic-dictionary.pages.dev", "icons": [ { "src": "icons/icon-72x72.png", @@ -49,10 +49,10 @@ ], "serviceworker": { "src": "sw.prod.js", - "scope": "https://interslavic-dictionary.com/", + "scope": "https://pr-342.interslavic-dictionary.pages.dev", "update_via_cache": "none" }, - "start_url": "https://interslavic-dictionary.com/", + "start_url": "https://pr-342.interslavic-dictionary.pages.dev", "background_color": "#272727", "display": "standalone", "orientation": "portrait-primary",