From 737a7696cfbe24902250bcec6378b47cb3294cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sun, 23 Jul 2023 18:07:20 +0200 Subject: [PATCH] Clean the old cache --- pwa/sw.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pwa/sw.js b/pwa/sw.js index 6620dee..016d591 100644 --- a/pwa/sw.js +++ b/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}`);