wait until serviceWorker activate to precache
This commit is contained in:
parent
94f1eabbc7
commit
883f2bc0f9
|
@ -13,12 +13,12 @@ const VERSIONED_ASSET = /\.[A-Fa-f0-9]{8}\.(js|css|png|svg|jpg)$/;
|
||||||
const DOWNLOAD_URL = /\/api\/download\/([A-Fa-f0-9]{4,})/;
|
const DOWNLOAD_URL = /\/api\/download\/([A-Fa-f0-9]{4,})/;
|
||||||
const FONT = /\.woff2?$/;
|
const FONT = /\.woff2?$/;
|
||||||
|
|
||||||
self.addEventListener('install', event => {
|
self.addEventListener('install', () => {
|
||||||
event.waitUntil(precache());
|
self.skipWaiting();
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('activate', event => {
|
self.addEventListener('activate', event => {
|
||||||
event.waitUntil(self.clients.claim().then(cleanCache));
|
event.waitUntil(self.clients.claim().then(precache));
|
||||||
});
|
});
|
||||||
|
|
||||||
async function decryptStream(id) {
|
async function decryptStream(id) {
|
||||||
|
@ -84,10 +84,15 @@ async function decryptStream(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function precache() {
|
async function precache() {
|
||||||
const cache = await caches.open(version);
|
try {
|
||||||
const images = assets.match(IMAGES);
|
await cleanCache();
|
||||||
await cache.addAll(images);
|
const cache = await caches.open(version);
|
||||||
return self.skipWaiting();
|
const images = assets.match(IMAGES);
|
||||||
|
await cache.addAll(images);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
// cache will get populated on demand
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cleanCache() {
|
async function cleanCache() {
|
||||||
|
|
Loading…
Reference in New Issue