-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): remove service-worker for bad cache (#21)
- Loading branch information
Showing
1 changed file
with
0 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}) | ||
); | ||
}) | ||
); | ||
}); | ||