Skip to content

Instantly share code, notes, and snippets.

@devNoiseConsulting
Created January 12, 2018 21:12
Show Gist options
  • Select an option

  • Save devNoiseConsulting/f856c42f3da77364a7b080cbf0c22660 to your computer and use it in GitHub Desktop.

Select an option

Save devNoiseConsulting/f856c42f3da77364a7b080cbf0c22660 to your computer and use it in GitHub Desktop.
Pay attention to which variable you're using!
// Wrong!!!
self.addEventListener('activate', function(event) {
var cacheWhitelist = ['v2'];
event.waitUntil(
// TODO: remove the old cache
caches.keys().then(function(keyList) {
return Promise.all(
keyList.map(function(key) {
if (cacheWhitelist.indexOf(key) === -1) {
console.log(key);
return caches.delete(key);
}
})
);
})
);
});
// Right!
self.addEventListener('activate', function(event) {
var cacheWhitelist = ['v2'];
event.waitUntil(
// TODO: remove the old cache
caches.keys().then(function(keyList) {
return Promise.all(
keyList.map(function(key) {
if (key.indexOf(cacheWhitelist) === -1) {
return caches.delete(key);
}
})
);
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment