-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsw.js
More file actions
43 lines (38 loc) · 980 Bytes
/
sw.js
File metadata and controls
43 lines (38 loc) · 980 Bytes
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
/**
* 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",
"/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);
})
);
});