-
Notifications
You must be signed in to change notification settings - Fork 17
/
sw.js
35 lines (30 loc) · 905 Bytes
/
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
32
33
34
35
/**
* Looptap Service worker
*/
const version = "1.1.6";
const currentCacheName = "looptap-v" + version;
self.addEventListener("install", function(e) {
console.log("Install event triggered. New updates available.");
const filesToCache = ["/", "/favicon.ico", "/vue.min.js", "/style.css", "/script.js", "/manifest.json"];
// Deleting the previous version of cache
e.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter((cacheName) => cacheName != currentCacheName).map((cacheName) => caches.delete(cacheName))
);
})
);
// add the files to cache
e.waitUntil(
caches.open(currentCacheName).then(function(cache) {
return cache.addAll(filesToCache);
})
);
});
self.addEventListener("fetch", function(event) {
event.respondWith(
caches.match(event.request).then(function(cache) {
return cache || fetch(event.request);
})
);
});