fix service worker caching in firefox

This commit is contained in:
Nolan Lawson 2018-03-22 22:30:48 -07:00
parent cd968245e1
commit 84ed526327
1 changed files with 7 additions and 5 deletions

View File

@ -14,7 +14,7 @@ const cached = new Set(toCache)
const routes = __routes__
self.addEventListener('install', event => {
event.waitUntil((async function () {
event.waitUntil((async () => {
let cache = await caches.open(ASSETS)
await cache.addAll(toCache)
self.skipWaiting()
@ -22,7 +22,7 @@ self.addEventListener('install', event => {
})
self.addEventListener('activate', event => {
event.waitUntil((async function () {
event.waitUntil((async () => {
let keys = await caches.keys()
// delete old caches
for (let key of keys) {
@ -47,10 +47,11 @@ self.addEventListener('fetch', event => {
return
}
event.respondWith((async function () {
event.respondWith((async () => {
// always serve assets and webpack-generated files from cache
if (url.origin === self.origin && cached.has(url.pathname)) {
return caches.match(req)
let cache = await caches.open(ASSETS)
return cache.match(req)
}
// for pages, you might want to serve a shell `index.html` file,
@ -59,7 +60,8 @@ self.addEventListener('fetch', event => {
if (url.origin === self.origin &&
routes.find(route => route.pattern.test(url.pathname))) {
return caches.match('/index.html')
let cache = await caches.open(ASSETS)
return cache.match('/index.html')
}
// For these GET requests, go cache-first