-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
39 lines (36 loc) · 1.5 KB
/
sw.js
File metadata and controls
39 lines (36 loc) · 1.5 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
const CACHE = 'rag-v14';
const ASSETS = [
'./', './index.html', './deals.html', './directory.html', './team.html',
'./mortgage.html', './blog.html', './buyer-resources.html', './seller-resources.html',
'./listing-detail.html', './command-center.html', './contacts.html',
'./pipeline.html', './commission.html', './signals.html', './email-templates.html',
'./analytics.html', './settings.html',
'./assets/css/styles.css', './assets/js/utils.js', './assets/js/public.js',
'./assets/js/command.js', './assets/js/eve.js', './assets/js/gps-fallback-map.js',
'./assets/js/auth.js', './assets/js/resolver.js', './assets/js/compiler.js',
'./assets/js/settings.js', './data/bootstrap.js', './data/team.json',
'./data/blog/posts.json', './manifest.json'
];
self.addEventListener('install', e => {
e.waitUntil(caches.open(CACHE).then(c => c.addAll(ASSETS)).then(() => self.skipWaiting()));
});
self.addEventListener('activate', e => {
e.waitUntil(caches.keys().then(keys => Promise.all(
keys.filter(k => k !== CACHE).map(k => caches.delete(k))
)).then(() => self.clients.claim()));
});
self.addEventListener('fetch', e => {
if (e.request.method !== 'GET') return;
e.respondWith(
caches.match(e.request).then(cached => {
const fetched = fetch(e.request).then(res => {
if (res.ok) {
const clone = res.clone();
caches.open(CACHE).then(c => c.put(e.request, clone));
}
return res;
}).catch(() => cached);
return cached || fetched;
})
);
});