Skip to content

Commit

Permalink
Fix sw
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic16x committed Nov 23, 2024
1 parent 88bbf02 commit 153e6b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 23 additions & 3 deletions src/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions static/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 153e6b8

Please sign in to comment.