From d65db3f6b34162082bed1fcaa49910ee1209b9e3 Mon Sep 17 00:00:00 2001 From: Nevermore <15972699417@163.com> Date: Sat, 30 Nov 2024 12:38:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0pwa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/sw.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 public/sw.js diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 00000000..854e130f --- /dev/null +++ b/public/sw.js @@ -0,0 +1,24 @@ +// public/sw.js +self.addEventListener('install', (e) => { + self.skipWaiting(); +}); +self.addEventListener('activate', (e) => { + self.registration + .unregister() + .then(() => self.clients.matchAll()) + .then((clients) => { + clients.forEach((client) => { + if (client instanceof WindowClient) client.navigate(client.url); + }); + return Promise.resolve(); + }) + .then(() => { + self.caches.keys().then((cacheNames) => { + Promise.all( + cacheNames.map((cacheName) => { + return self.caches.delete(cacheName); + }) + ); + }); + }); +}); \ No newline at end of file