diff --git a/CHANGELOG.md b/CHANGELOG.md index 59048daf44..4c0dee4674 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,18 @@ Mark items as `Added`, `Changed`, `Fixed`, `Modified`, `Removed`, `Untested Features`, `Upcoming Features`, `Known Issues` -## 6.0.1 - 2024-05-16 +## 6.0.1 - 2024-05-21 `Added` **forms-flow-web-root-config** * Added resouce bundle for Spanish +`Fixed` + +**forms-flow-web-root-config** +* Fixed service worker cache issue + ## 6.0.0 - 2024-04-05 `Added` diff --git a/forms-flow-web-root-config/public/worker.js b/forms-flow-web-root-config/public/worker.js index 078a0e1ef6..fde07b7781 100644 --- a/forms-flow-web-root-config/public/worker.js +++ b/forms-flow-web-root-config/public/worker.js @@ -1,54 +1,51 @@ const CACHE_NAME = "FORMS-FLOW-AI-WEB"; -// Set this to true for production const doCache = true; const urlsToCache = [ - "/", - "/form", - "/task", - "/application", "/manifest.json", "/favicon.ico", - "/config/kc/keycloak.json", - "/spinner.gif", - "/logo.png", - "/simple-logo.png", ]; + // Install a service worker self.addEventListener("install", (event) => { if (doCache) { - // Perform install steps - // console.log('Attempting to install service worker and cache static assets'); event.waitUntil( caches.open(CACHE_NAME).then((cache) => { - // console.log("Opened cache"); - cache - .addAll( - urlsToCache.map((urlsToCache) => { - return new Request(urlsToCache, { mode: "no-cors" }); - }) - ) - .then(() => - console.log("All resources have been fetched and cached.") - ); + return cache.addAll( + urlsToCache.map((url) => { + return new Request(url, { mode: "no-cors" }); + }) + ); }) ); } }); +// Fetch event self.addEventListener("fetch", (event) => { event.respondWith( - caches.match(event.request).then((response) => { - // Cache hit - return response - if (response) { + fetch(event.request) + .then((response) => { + // Clone the response for caching + const responseClone = response.clone(); + + // Cache the fetched response + caches.open(CACHE_NAME).then((cache) => { + cache.put(event.request, responseClone); + }); + return response; - } - return fetch(event.request); - }) + }) + .catch(() => { + // If fetch fails, try to respond with the cached version + return caches.match(event.request).then((cachedResponse) => { + return cachedResponse || new Response(null, { status: 404 }); + }); + }) ); }); -// Update a service worker +// Activate event self.addEventListener("activate", (event) => { const cacheWhitelist = [CACHE_NAME]; event.waitUntil( @@ -64,8 +61,8 @@ self.addEventListener("activate", (event) => { ); }); +// Message event self.addEventListener("message", (event) => { - //console.log("message",event.data.action); if (event.data.action === "skipWaiting") { self.skipWaiting(); } diff --git a/forms-flow-web-root-config/src/worker.js b/forms-flow-web-root-config/src/worker.js deleted file mode 100644 index 7bba678a1a..0000000000 --- a/forms-flow-web-root-config/src/worker.js +++ /dev/null @@ -1,76 +0,0 @@ -const CACHE_NAME = "FORMS-FLOW-AI-WEB"; -// Set this to true for production -const doCache = true; - -const urlsToCache = [ - "/", - "/form", - "/task", - "/application", - "/manifest.json", - "/favicon.ico", - "/config/kc/keycloak.json", - "/spinner.gif", - "/logo.png", - "/simple-logo.png", -]; -// Install a service worker -self.addEventListener("install", (event) => { - if (doCache) { - // Perform install steps - // console.log('Attempting to install service worker and cache static assets'); - event.waitUntil( - caches.open(CACHE_NAME).then((cache) => { - console.log("Opened cache"); - try { - cache.addAll( - urlsToCache.map((urlToCache) => { - return new Request(urlToCache, { mode: "no-cors" }); - }) - ).then(() => - console.log("All resources have been fetched and cached.") - ).catch((error) => { - console.log("Error caching resources:", error); - }); - } catch (error) { - console.log("Cache operation failed:", error); - } - }) - ); - } -}); - -self.addEventListener("fetch", (event) => { - event.respondWith( - caches.match(event.request).then((response) => { - // Cache hit - return response - if (response) { - return response; - } - return fetch(event.request); - }) - ); -}); - -// Update a service worker -self.addEventListener("activate", (event) => { - const cacheWhitelist = [CACHE_NAME]; - event.waitUntil( - caches.keys().then((cacheNames) => { - return Promise.all( - cacheNames.map((cacheName) => { - if (cacheWhitelist.indexOf(cacheName) === -1) { - return caches.delete(cacheName); - } - }) - ); - }) - ); -}); - -self.addEventListener("message", (event) => { - //console.log("message",event.data.action); - if (event.data.action === "skipWaiting") { - self.skipWaiting(); - } -});