From 0dcbfd746e00b722d5b378f760684428f022e5ff Mon Sep 17 00:00:00 2001 From: Jesse <43443357+jessegpt@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:41:00 +0400 Subject: [PATCH] fix serviceWorker cache --- public/serviceWorker.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/public/serviceWorker.js b/public/serviceWorker.js index f5a24b70176..2e1d60b98d2 100644 --- a/public/serviceWorker.js +++ b/public/serviceWorker.js @@ -1,15 +1,21 @@ const CHATGPT_NEXT_WEB_CACHE = "chatgpt-next-web-cache"; +importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.0.0/workbox-sw.js'); + self.addEventListener("activate", function (event) { console.log("ServiceWorker activated."); }); -self.addEventListener("install", function (event) { - event.waitUntil( - caches.open(CHATGPT_NEXT_WEB_CACHE).then(function (cache) { - return cache.addAll([]); - }), - ); +workbox.core.clientsClaim(); +self.addEventListener("message", (event) => { + if (event.data && event.data.type === "SKIP_WAITING") { + self.skipWaiting(); + } }); -self.addEventListener("fetch", (e) => {}); +workbox.routing.registerRoute( + new RegExp('/*'), + new workbox.strategies.StaleWhileRevalidate({ + cacheName: CHATGPT_NEXT_WEB_CACHE + }) +);