-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
77 lines (73 loc) · 2.09 KB
/
sw.js
File metadata and controls
77 lines (73 loc) · 2.09 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
// HMS Tracker — Service Worker v1.0
// Cache-first strategy, offline-first PWA
const CACHE_NAME = 'hms-tracker-v1.0.0';
const ASSETS = [
'/',
'/index.html',
'/manifest.json',
'/prompts.json',
'/css/main.css',
'/css/base/reset.css',
'/css/base/variables.css',
'/css/base/typography.css',
'/css/components/navbar.css',
'/css/components/fab.css',
'/css/components/modal.css',
'/css/components/cards.css',
'/css/components/buttons.css',
'/css/components/forms.css',
'/css/components/toast.css',
'/css/components/pin.css',
'/css/components/progress.css',
'/css/pages/dashboard.css',
'/css/pages/assets.css',
'/css/pages/expenses.css',
'/css/pages/goals.css',
'/css/pages/zakat.css',
'/js/main.js',
'/js/state.js',
'/js/data.js',
'/js/render.js',
'/js/utils.js',
'/js/router.js',
'/js/stores/assetsStore.js',
'/js/stores/transactionsStore.js',
'/js/stores/goalsStore.js',
'/js/stores/zakatStore.js',
'/js/stores/settingsStore.js',
'/js/pages/dashboard.js',
'/js/pages/assets.js',
'/js/pages/expenses.js',
'/js/pages/goals.js',
'/js/pages/zakat.js',
'/assets/sprites.svg',
];
// Install — cache all assets
self.addEventListener('install', e => {
e.waitUntil(
caches.open(CACHE_NAME).then(cache => cache.addAll(ASSETS)).then(() => self.skipWaiting())
);
});
// Activate — clean old caches
self.addEventListener('activate', e => {
e.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(k => k !== CACHE_NAME).map(k => caches.delete(k)))
).then(() => self.clients.claim())
);
});
// Fetch — cache-first, network fallback
self.addEventListener('fetch', e => {
if (e.request.method !== 'GET') return;
e.respondWith(
caches.match(e.request).then(cached => {
if (cached) return cached;
return fetch(e.request).then(response => {
if (!response || response.status !== 200) return response;
const clone = response.clone();
caches.open(CACHE_NAME).then(cache => cache.put(e.request, clone));
return response;
}).catch(() => caches.match('/index.html'));
})
);
});