-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathServiceWorker.js
More file actions
35 lines (33 loc) · 787 Bytes
/
ServiceWorker.js
File metadata and controls
35 lines (33 loc) · 787 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
var CACHE_NAME = "$(ProjectName)";
var CACHED_URLS = [
"$(ProjectHTML)",
(FileList)
]
self.addEventListener("install", function(event) {
event.waitUntil(
caches.open(CACHE_NAME).then(function(cache) {
return cache.addAll(CACHED_URLS)
})
)
})
self.addEventListener("fetch", function(event) {
event.respondWith(
fetch(event.request).catch(function() {
return caches.match(event.request).then (
function(response) {
if (response) {
return response
}
else {
if (event.request.headers.get("accept").includes("text/html")) {
return caches.match("$(ProjectHTML)")
}
else {
return false
}
}
}
)
})
)
})