From 5f670f6eb3aaf827caacfc8ad51905bac77f1e36 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Mon, 19 Mar 2018 20:24:33 -0700 Subject: [PATCH] fix offline support for themes --- templates/service-worker.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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) }