Skip to content

Commit

Permalink
🚑 [Hotfix] fixed cache issue (#2055)
Browse files Browse the repository at this point in the history
* [Hotfix] fixed cache issue

* Hotfix : updated change log
  • Loading branch information
shuhaib-aot authored May 21, 2024
1 parent 2bb1e3f commit e8940ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 106 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
55 changes: 26 additions & 29 deletions forms-flow-web-root-config/public/worker.js
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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();
}
Expand Down
76 changes: 0 additions & 76 deletions forms-flow-web-root-config/src/worker.js

This file was deleted.

0 comments on commit e8940ab

Please sign in to comment.