forked from mystiq/hydrogen-web
wip
This commit is contained in:
parent
5ad600cd56
commit
6c3722a1c0
1 changed files with 38 additions and 15 deletions
|
@ -43,9 +43,32 @@ self.addEventListener('activate', (event) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('fetch', (event) => {
|
self.addEventListener('fetch', (event) => {
|
||||||
|
console.log("new fetch event in sw", event);
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
caches.open(cacheName)
|
caches.open(cacheName)
|
||||||
.then(cache => cache.match(event.request))
|
.then(cache => cache.match(event.request))
|
||||||
.then((response) => response || fetch(event.request))
|
.then((response) => response || fetch(event.request))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// service-worker.js
|
||||||
|
// Listen to the request
|
||||||
|
self.addEventListener('message', (event) => {
|
||||||
|
if (event.data && event.data.type === 'PING') {
|
||||||
|
// Select who we want to respond to
|
||||||
|
self.clients.matchAll({
|
||||||
|
includeUncontrolled: true,
|
||||||
|
type: 'window',
|
||||||
|
}).then((clients) => {
|
||||||
|
if (clients && clients.length) {
|
||||||
|
// Send a response - the clients
|
||||||
|
// array is ordered by last focused
|
||||||
|
clients[0].postMessage({
|
||||||
|
type: 'PONG',
|
||||||
|
files: OFFLINE_FILES,
|
||||||
|
version: VERSION,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue