-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
93 lines (85 loc) Β· 2.58 KB
/
Copy pathsw.js
File metadata and controls
93 lines (85 loc) Β· 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// ==============================================
// π AZURA AI SERVICE WORKER - VERSI BETUL v3
// ==============================================
const CACHE_NAME = 'azura-ai-cache-v3'; // Tukar version!
const FILES_TO_CACHE = [
'./',
'./index.html',
'./manifest.json',
'./icon-192.png',
'./icon-512.png',
'./icon-192-maskable.png',
'./icon-512-maskable.png'
// Jangan cache API calls
];
// ==============================================
// π¦ INSTALL - Cache semua fail
// ==============================================
self.addEventListener('install', event => {
console.log('βοΈ Installing Service Worker v3...');
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('π¦ Caching files...');
return cache.addAll(FILES_TO_CACHE);
})
.then(() => {
console.log('β
Cache siap!');
return self.skipWaiting(); // Aktifkan segera
})
);
});
// ==============================================
:// π ACTIVATE - BUANG CACHE LAMA (PENTING!)
// ==============================================
self.addEventListener('activate', event => {
console.log('β‘ Activating new Service Worker...');
event.waitUntil(
caches.keys().then(keys => {
return Promise.all(
keys.map(key => {
// π₯ BUANG semua cache version lama
if (key !== CACHE_NAME) {
console.log(`ποΈ Deleting old cache: ${key}`);
return caches.delete(key);
}
})
);
}).then(() => {
console.log('β
Service Worker v3 sedia!');
// π₯ Ambil alih semua tabs
return self.clients.claim();
})
);
});
// ==============================================
:// π FETCH - Cache First, Network Second
// ==============================================
self.addEventListener('fetch', event => {
const url = event.request.url;
// π₯ JANGAN cache API calls
if (url.includes('googleapis.com') ||
url.includes('workers.dev') ||
url.includes('gateway.pinata.cloud') ||
url.includes('api.')) {
return;
}
event.respondWith(
caches.match(event.request)
.then(cachedResponse => {
if (cachedResponse) {
return cachedResponse;
}
return fetch(event.request).then(response => {
// Cache untuk lanjutan
if (response.status === 200) {
const responseClone = response.clone();
caches.open(CACHE_NAME).then(cache => {
cache.put(event.request, responseClone);
});
}
return response;
});
})
);
});