You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
645 B
JavaScript
29 lines
645 B
JavaScript
2 years ago
|
const version = '1.0.0';
|
||
|
const cacheName = `blackscreen-${version}`;
|
||
|
|
||
|
self.addEventListener('install', e => {
|
||
|
e.waitUntil(
|
||
|
caches.open(cacheName).then(cache => {
|
||
|
return cache.addAll([
|
||
|
`/`,
|
||
|
`/index.html`
|
||
|
])
|
||
|
.then(() => self.skipWaiting());
|
||
|
})
|
||
|
);
|
||
|
});
|
||
|
|
||
|
self.addEventListener('activate', event => {
|
||
|
event.waitUntil(self.clients.claim());
|
||
|
});
|
||
|
|
||
|
self.addEventListener('fetch', event => {
|
||
|
event.respondWith(
|
||
|
caches.open(cacheName)
|
||
|
.then(cache => cache.match(event.request, { ignoreSearch: true }))
|
||
|
.then(response => {
|
||
|
return response || fetch(event.request);
|
||
|
})
|
||
|
);
|
||
|
});
|