Compare commits

..

No commits in common. "b2347b04663f600816e142c1199bbd7118a676a9" and "bec8fcdce1d385ba77edaa838f4ddf61c29371b1" have entirely different histories.

2 changed files with 9 additions and 28 deletions

View file

@ -11,21 +11,14 @@
navigator.serviceWorker.register('/service-worker.js'); navigator.serviceWorker.register('/service-worker.js');
}); });
if (BroadcastChannel) { const channel = new BroadcastChannel('sw-messages');
const channel = new BroadcastChannel('sw-messages'); channel.addEventListener('message', (event) => {
channel.addEventListener('message', (event) => { new Toast({ target: node });
console.log(event.data); });
new Toast({ target: node });
});
} else {
navigator.serviceWorker.addEventListener('message', (evt) => {
console.log(evt.data);
new Toast({ target: node });
});
}
navigator.serviceWorker.ready.then((registration) => { navigator.serviceWorker.ready.then((registration) => {
registration.active.postMessage('Save client'); console.log(registration);
console.log('registered service worker');
}); });
} }
}); });

View file

@ -14,12 +14,6 @@ const ASSETS = [
...prerendered // dynamic routes ...prerendered // dynamic routes
]; ];
let client;
addEventListener('message', event => {
client = event.source;
});
self.addEventListener('install', (event) => { self.addEventListener('install', (event) => {
// Create a new cache and add all files to it // Create a new cache and add all files to it
async function addFilesToCache() { async function addFilesToCache() {
@ -30,7 +24,7 @@ self.addEventListener('install', (event) => {
event.waitUntil(addFilesToCache()); event.waitUntil(addFilesToCache());
}); });
const channel = new BroadcastChannel('sw-messages');
self.addEventListener('activate', (event) => { self.addEventListener('activate', (event) => {
@ -42,13 +36,7 @@ self.addEventListener('activate', (event) => {
} }
event.waitUntil(deleteOldCaches()); event.waitUntil(deleteOldCaches());
let channel; channel.postMessage({title: 'Cache downloaded!'});
if(BroadcastChannel) {
channel = new BroadcastChannel('sw-messages');
channel.postMessage({title: 'Cache Downloaded'});
} else {
client.postMessage("Cache Downloaded")
}
}); });
self.addEventListener('fetch', (event) => { self.addEventListener('fetch', (event) => {