xenux4u commited on
Commit
b5d9eb9
Β·
verified Β·
1 Parent(s): c397617

Update static/sw.js

Browse files
Files changed (1) hide show
  1. static/sw.js +22 -36
static/sw.js CHANGED
@@ -1,48 +1,34 @@
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
  });
 
1
  // ─────────────────────────────────────────────
2
+ // ORBIT Service Worker β€” sw.js (FAILSAFE MODE)
3
  // ─────────────────────────────────────────────
4
 
5
+ const CACHE_NAME = "orbit-failsafe-v1";
 
 
 
 
 
6
 
7
+ // Langsung aktif tanpa nunggu
8
  self.addEventListener("install", (event) => {
9
+ self.skipWaiting();
 
 
 
 
 
 
 
10
  });
11
 
12
+ // Bersihkan semua cache lama yang bikin web ERR_FAILED
13
  self.addEventListener("activate", (event) => {
14
+ event.waitUntil(
15
+ caches.keys().then((cacheNames) => {
16
+ return Promise.all(
17
+ cacheNames.map((cacheName) => {
18
+ return caches.delete(cacheName);
19
+ })
20
+ );
21
+ })
22
+ );
23
+ self.clients.claim();
24
  });
25
 
26
+ // PASS-THROUGH: Jangan pernah block request, langsung tembak ke server asli
27
  self.addEventListener("fetch", (event) => {
28
+ event.respondWith(
29
+ fetch(event.request).catch(function(error) {
30
+ console.error('[PWA] Network request Failed. Serving page offline is disabled to prevent ERR_FAILED.');
31
+ throw error;
32
+ })
33
+ );
 
 
 
 
 
 
 
34
  });