Clean the old cache
This commit is contained in:
parent
cc515d57c6
commit
737a7696cf
1 changed files with 17 additions and 0 deletions
17
pwa/sw.js
17
pwa/sw.js
|
@ -22,6 +22,23 @@ self.addEventListener('install', (event) => {
|
|||
}));
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (e) => {
|
||||
e.waitUntil(
|
||||
caches.keys().then((keyList) =>
|
||||
Promise.all(
|
||||
keyList.map((key) => {
|
||||
if (key != cache_name) {
|
||||
log_message(`Cleaning cache: ${key}`);
|
||||
return caches.delete(key);
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
e.waitUntil(clients.claim());
|
||||
log_message('Active');
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
if (!(event.request.url.startsWith('https:') || event.request.url.startsWith('http:'))) {
|
||||
log_message(`Fetching resource failed: invalid protocol: ${event.request.url}`);
|
||||
|
|
Loading…
Reference in a new issue