Skip to content

Commit

Permalink
Service Worker takes control as soon as new version installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremia Kimelman committed Jul 7, 2017
1 parent 1bd2366 commit bc82f33
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions public/sw.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable no-unused-vars */
const VERSION = 1
const CACHE = 'crime-data-explorer'

self.addEventListener('install', event => {
self.skipWaiting()
event.waitUntil(
caches.open(CACHE).then(cache => {
cache.addAll([
'/cde-logo.png',
'/fbi-logo.png',
'/github.svg',
'/twitter.svg',
'/chevron-down-navy.svg',
'/img/cde-logo.png',
'/img/fbi-logo.png',
'/img/loading.svg',
'/img/github.svg',
'/img/twitter.svg',
'/img/chevron-down-navy.svg',
'/data/geo-usa-state.json',
'/data/usa-state-svg.json',
])
Expand All @@ -30,13 +30,16 @@ self.addEventListener('install', event => {

self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
const promises = cacheNames
.filter(cacheName => cacheName === CACHE)
.map(cacheName => caches.delete(cacheName))

return Promise.all(promises)
}),
caches
.keys()
.then(cacheNames =>
Promise.all(
cacheNames
.filter(cacheName => cacheName === CACHE)
.map(cacheName => caches.delete(cacheName)),
),
)
.then(() => self.clients.claim()),
)
})

Expand Down

0 comments on commit bc82f33

Please sign in to comment.