Update static/sw.js
Browse files- static/sw.js +42 -7
static/sw.js
CHANGED
|
@@ -1,13 +1,48 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
});
|
| 5 |
|
| 6 |
-
self.addEventListener(
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
});
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
});
|
|
|
|
| 1 |
+
// βββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
+
// ORBIT Service Worker β sw.js (V2 Safe Mode)
|
| 3 |
+
// βββββββββββββββββββββββββββββββββββββββββββββ
|
| 4 |
+
|
| 5 |
+
const CACHE_NAME = "orbit-v2";
|
| 6 |
+
const APP_SHELL = [
|
| 7 |
+
"/",
|
| 8 |
+
"/static/js/script.js",
|
| 9 |
+
"/manifest.json"
|
| 10 |
+
];
|
| 11 |
+
|
| 12 |
+
self.addEventListener("install", (event) => {
|
| 13 |
+
event.waitUntil(
|
| 14 |
+
caches.open(CACHE_NAME).then((cache) => {
|
| 15 |
+
return Promise.allSettled(
|
| 16 |
+
APP_SHELL.map(url => cache.add(url).catch(err => console.warn("[SW] Gagal cache:", url, err)))
|
| 17 |
+
);
|
| 18 |
+
})
|
| 19 |
+
);
|
| 20 |
+
self.skipWaiting();
|
| 21 |
});
|
| 22 |
|
| 23 |
+
self.addEventListener("activate", (event) => {
|
| 24 |
+
event.waitUntil(
|
| 25 |
+
caches.keys().then((keys) =>
|
| 26 |
+
Promise.all(
|
| 27 |
+
keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k))
|
| 28 |
+
)
|
| 29 |
+
)
|
| 30 |
+
);
|
| 31 |
+
self.clients.claim();
|
| 32 |
});
|
| 33 |
|
| 34 |
+
self.addEventListener("fetch", (event) => {
|
| 35 |
+
const url = new URL(event.request.url);
|
| 36 |
+
|
| 37 |
+
if (url.pathname.startsWith("/api/") || url.pathname.startsWith("/auth/")) {
|
| 38 |
+
return;
|
| 39 |
+
}
|
| 40 |
|
| 41 |
+
event.respondWith(
|
| 42 |
+
caches.match(event.request).then((cached) => {
|
| 43 |
+
if (cached) return cached;
|
| 44 |
+
return fetch(event.request).catch(() => {
|
| 45 |
+
});
|
| 46 |
+
})
|
| 47 |
+
);
|
| 48 |
});
|