-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
31 lines (28 loc) · 1.02 KB
/
sw.js
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
const dynamicCache = "tt2-optimizer-dynamic-v5.26.03";
self.addEventListener('install', function(event){
//console.log('service worker has been installed')
event.waitUntil(
caches.open(dynamicCache)
);
});
self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then((keyList) => Promise.all(keyList.map((key) => {if(key !== dynamicCache)caches.delete(key)})))
)
});
self.addEventListener('fetch', (e) => {
//checkVersion(e);
e.respondWith(
caches.match(e.request).then((response) => response || fetch(e.request).then(fetchRes => {
return caches.open(dynamicCache).then(cache => {
if(fetchRes.status === 200 && !e.request.url.endsWith("save") && !e.request.url.endsWith("load")){
cache.put(e.request.url, fetchRes.clone());
} else if(e.request.url.endsWith("save") || e.request.url.endsWith("load") ) {
console.log("not caching a db call")
}
return fetchRes;
})
})
)
);
});