Skip to content

Commit 511972c

Browse files
committed
[sw] cleanning up deprecated, un-namespaced caches to prevent dead caches
1 parent f0a3f43 commit 511972c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sw.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ self.addEventListener('install', e => {
9999
* waitUntil(): activating ====> activated
100100
*/
101101
self.addEventListener('activate', event => {
102-
// TODO: consider some cleanning up.
102+
// delete old deprecated caches.
103+
caches.keys().then(cacheNames => Promise.all(
104+
cacheNames
105+
.filter(cacheName => ['precache-v1', 'runtime'].includes(cacheName))
106+
.map(cacheName => caches.delete(cacheName))
107+
))
103108
console.log('service worker activated.')
104109
event.waitUntil(self.clients.claim());
105110
});

0 commit comments

Comments
 (0)