fix pwa caching for fresh settings and env changes
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
const CACHE_NAME = "nouri-v0-5-0";
|
const CACHE_NAME = "nouri-v0-5-1";
|
||||||
const APP_SHELL = [
|
const STATIC_ASSETS = [
|
||||||
"/",
|
|
||||||
"/static/css/styles.css",
|
"/static/css/styles.css",
|
||||||
"/static/js/theme.js",
|
"/static/js/theme.js",
|
||||||
"/static/js/ui.js",
|
"/static/js/ui.js",
|
||||||
@@ -13,7 +12,7 @@ const APP_SHELL = [
|
|||||||
|
|
||||||
self.addEventListener("install", (event) => {
|
self.addEventListener("install", (event) => {
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)).then(() => self.skipWaiting())
|
caches.open(CACHE_NAME).then((cache) => cache.addAll(STATIC_ASSETS)).then(() => self.skipWaiting())
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -27,9 +26,32 @@ self.addEventListener("activate", (event) => {
|
|||||||
|
|
||||||
self.addEventListener("fetch", (event) => {
|
self.addEventListener("fetch", (event) => {
|
||||||
if (event.request.method !== "GET") return;
|
if (event.request.method !== "GET") return;
|
||||||
|
|
||||||
|
const requestUrl = new URL(event.request.url);
|
||||||
|
const isStaticAsset =
|
||||||
|
requestUrl.origin === self.location.origin &&
|
||||||
|
(
|
||||||
|
requestUrl.pathname.startsWith("/static/")
|
||||||
|
|| requestUrl.pathname === "/app.webmanifest"
|
||||||
|
|| requestUrl.pathname === "/service-worker.js"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (event.request.mode === "navigate") {
|
||||||
|
event.respondWith(
|
||||||
|
fetch(event.request).catch(() => caches.match(event.request))
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isStaticAsset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
caches.match(event.request).then((cached) => {
|
caches.match(event.request).then((cached) => {
|
||||||
if (cached) return cached;
|
if (cached) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
return fetch(event.request).then((response) => {
|
return fetch(event.request).then((response) => {
|
||||||
if (!response || response.status !== 200 || response.type !== "basic") {
|
if (!response || response.status !== 200 || response.type !== "basic") {
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
Reference in New Issue
Block a user