diff --git a/templates/service-worker.js b/templates/service-worker.js index 2e31faf..0a12a27 100644 --- a/templates/service-worker.js +++ b/templates/service-worker.js @@ -3,9 +3,10 @@ const ASSETS = `cache${timestamp}` // `shell` is an array of all the files generated by webpack, // `assets` is an array of everything in the `assets` directory -const toCache = __shell__.concat(__assets__) +const assets = __assets__.map(file => file.startsWith('/') ? file : `/${file}`) +const toCache = __shell__.concat(assets) .filter(filename => !filename.endsWith('.map')) - .filter(filename => !filename.startsWith('apple-icon')) + .filter(filename => !filename.startsWith('/apple-icon')) const cached = new Set(toCache) // `routes` is an array of `{ pattern: RegExp }` objects that @@ -48,7 +49,7 @@ self.addEventListener('fetch', event => { event.respondWith((async function () { // always serve assets and webpack-generated files from cache - if (cached.has(url.pathname)) { + if (url.origin === self.origin && cached.has(url.pathname)) { return caches.match(req) }