Skip to content

Commit

Permalink
fix(client): remove service-worker for bad cache (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
junglesub authored Oct 9, 2024
1 parent 481982b commit 64fee5a
Showing 1 changed file with 0 additions and 49 deletions.
49 changes: 0 additions & 49 deletions src/main/front/public/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,49 +0,0 @@
const CACHE_NAME = "my-app-cache-v1";
const urlsToCache = [
"/",
"/index.html",
"/favicon.png",
"/manifest.json",
// Add any other assets or paths you want to cache
];

// Install event - caching assets
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
console.log("Opened cache");
return cache.addAll(urlsToCache);
})
);
});

// Fetch event - serve cached content when offline
self.addEventListener("fetch", (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
// Cache hit - return the cached response
if (response) {
return response;
}
// Fetch from network if not in cache
return fetch(event.request);
})
);
});

// Activate event - clean up old caches
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) {
// Delete outdated caches
return caches.delete(cacheName);
}
})
);
})
);
});

0 comments on commit 64fee5a

Please sign in to comment.