From 683e0857ec0f1b660be1894d62d777042943fbc7 Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Wed, 19 Dec 2018 14:27:33 -0800 Subject: [PATCH] fix: properly remove caches before removing service worker (#1655) --- scripts/service-worker.js | 15 +++++++++++++++ server.js | 1 + 2 files changed, 16 insertions(+) create mode 100644 scripts/service-worker.js diff --git a/scripts/service-worker.js b/scripts/service-worker.js new file mode 100644 index 000000000..f8f40fcc4 --- /dev/null +++ b/scripts/service-worker.js @@ -0,0 +1,15 @@ +self.addEventListener('install', function () { + self.skipWaiting() +}) + +self.addEventListener('activate', function (event) { + event.waitUntil( + caches.keys().then(function (cacheNames) { + return Promise.all( + cacheNames.map(function (cacheName) { + return caches.delete(cacheName) + }) + ) + }) + ) +}) diff --git a/server.js b/server.js index 24c57cfda..2781d2e73 100644 --- a/server.js +++ b/server.js @@ -44,6 +44,7 @@ app.use(compression()) app.use(helmet()) app.use(sass()) app.use('/scripts/index.js', browserify('scripts/index.js')) +app.get('/service-worker.js', (req, res) => res.sendFile(path.resolve(__dirname, 'scripts', 'service-worker.js'))) app.use(slashes(false)) app.use(cookieParser()) app.use(requestLanguage({