Clean the old cache

This commit is contained in:
Rodolphe Bréard 2023-07-23 18:07:20 +02:00
parent cc515d57c6
commit 737a7696cf

View file

@ -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}`);