Compare commits
2 commits
bec8fcdce1
...
b2347b0466
Author | SHA1 | Date | |
---|---|---|---|
b2347b0466 | |||
e4829976e4 |
2 changed files with 28 additions and 9 deletions
|
@ -11,14 +11,21 @@
|
|||
navigator.serviceWorker.register('/service-worker.js');
|
||||
});
|
||||
|
||||
if (BroadcastChannel) {
|
||||
const channel = new BroadcastChannel('sw-messages');
|
||||
channel.addEventListener('message', (event) => {
|
||||
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) => {
|
||||
console.log(registration);
|
||||
console.log('registered service worker');
|
||||
registration.active.postMessage('Save client');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -14,6 +14,12 @@ const ASSETS = [
|
|||
...prerendered // dynamic routes
|
||||
];
|
||||
|
||||
let client;
|
||||
|
||||
addEventListener('message', event => {
|
||||
client = event.source;
|
||||
});
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
// Create a new cache and add all files to it
|
||||
async function addFilesToCache() {
|
||||
|
@ -24,7 +30,7 @@ self.addEventListener('install', (event) => {
|
|||
event.waitUntil(addFilesToCache());
|
||||
});
|
||||
|
||||
const channel = new BroadcastChannel('sw-messages');
|
||||
|
||||
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
|
@ -36,7 +42,13 @@ self.addEventListener('activate', (event) => {
|
|||
}
|
||||
|
||||
event.waitUntil(deleteOldCaches());
|
||||
channel.postMessage({title: 'Cache downloaded!'});
|
||||
let channel;
|
||||
if(BroadcastChannel) {
|
||||
channel = new BroadcastChannel('sw-messages');
|
||||
channel.postMessage({title: 'Cache Downloaded'});
|
||||
} else {
|
||||
client.postMessage("Cache Downloaded")
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
|
|
Loading…
Reference in a new issue