-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
executable file
·73 lines (70 loc) · 2.83 KB
/
Copy pathsw.js
File metadata and controls
executable file
·73 lines (70 loc) · 2.83 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
// ── DEPLOY VERSION ────────────────────────────────────────────────────────────
// INCREMENT THIS ON EVERY PRODUCTION DEPLOY so users receive the latest files.
// Format: vailism-shell-vN (N = deploy number)
const CACHE_NAME = 'vailism-shell-v8';
const ASSETS_TO_CACHE = [
'/',
'/index.html',
'/details.html',
'/player.html', // was missing — player not served offline
'/style.css',
'/script.js',
'/details.js',
'/js/storage.js', // new shared storage module
'/js/watch-progress.js',
'/js/watchlist.js',
'/js/AuthManager.js',
'/js/cloud-sync.js',
'/favicon/favicon.ico',
'/logo.png'
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
console.log('[SW] Caching app shell v8');
return cache.addAll(ASSETS_TO_CACHE);
})
);
self.skipWaiting();
});
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys => {
return Promise.all(
keys.map(key => {
if (key !== CACHE_NAME) {
console.log('[SW] Removing old cache', key);
return caches.delete(key);
}
})
);
})
);
self.clients.claim();
});
self.addEventListener('fetch', event => {
// Only intercept same-origin requests (exclude API and external images/iframes)
if (event.request.url.startsWith(self.location.origin) && !event.request.url.includes('/api/')) {
// Stale-While-Revalidate: serve cached version immediately, update cache in background
event.respondWith(
caches.open(CACHE_NAME).then(cache => {
return cache.match(event.request).then(cachedResponse => {
const fetchPromise = fetch(event.request).then(networkResponse => {
if (networkResponse && networkResponse.status === 200 && networkResponse.type === 'basic') {
cache.put(event.request, networkResponse.clone());
}
return networkResponse;
}).catch(() => {
// Offline fallback for HTML pages
if (event.request.headers.get('accept') && event.request.headers.get('accept').includes('text/html')) {
return cache.match('/index.html');
}
return cachedResponse;
});
// Return cached immediately, fetch in background
return cachedResponse || fetchPromise;
});
})
);
}
});