-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceworker.js
28 lines (25 loc) · 882 Bytes
/
serviceworker.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
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)");
}
});
})
);
});