fix: address final PWA review findings
This commit is contained in:
+7
-3
@@ -10,7 +10,11 @@ self.addEventListener("install", (event) => {
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys()
|
||||
.then((keys) => Promise.all(keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))))
|
||||
.then((keys) => Promise.all(
|
||||
keys
|
||||
.filter((key) => key.startsWith("agendamax-shell-") && key !== CACHE_NAME)
|
||||
.map((key) => caches.delete(key))
|
||||
))
|
||||
.then(() => self.clients.claim())
|
||||
);
|
||||
});
|
||||
@@ -24,7 +28,7 @@ self.addEventListener("fetch", (event) => {
|
||||
event.respondWith(
|
||||
fetch(request)
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
if (request.credentials === "omit" && response.ok) {
|
||||
const copy = response.clone();
|
||||
void caches.open(CACHE_NAME).then((cache) => cache.put(request, copy));
|
||||
}
|
||||
@@ -36,7 +40,7 @@ self.addEventListener("fetch", (event) => {
|
||||
}
|
||||
|
||||
const cacheableDestination = new Set(["script", "style", "image", "font", "manifest", "worker"]);
|
||||
if (!cacheableDestination.has(request.destination)) return;
|
||||
if (request.credentials !== "omit" || !cacheableDestination.has(request.destination)) return;
|
||||
|
||||
event.respondWith(
|
||||
caches.match(request).then((cached) => {
|
||||
|
||||
Reference in New Issue
Block a user