forked from rianadon/CheckPCR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
114 lines (108 loc) · 2.81 KB
/
service-worker.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* Script to prefretch resources so that the page can be displayed offline.
* The code is adapted from http://www.html5rocks.com/en/tutorials/service-worker/introduction/.
*/
importScripts('serviceworker-cache-polyfill.js');
var CACHE_VERSION = '2.23.0';
var CACHE_NAME = 'checkpcr-cache-v1';
var urlsToCache = [
"/",
"index.html",
"font/material-design-icons/MaterialIcons-Regular.eot",
"font/material-design-icons/MaterialIcons-Regular.ttf",
"font/material-design-icons/MaterialIcons-Regular.woff",
"font/material-design-icons/MaterialIcons-Regular.woff2",
"font/roboto/Roboto-Bold.ttf",
"font/roboto/Roboto-Bold.woff",
"font/roboto/Roboto-Bold.woff2",
"font/roboto/Roboto-Light.ttf",
"font/roboto/Roboto-Light.woff",
"font/roboto/Roboto-Light.woff2",
"font/roboto/Roboto-Medium.ttf",
"font/roboto/Roboto-Medium.woff",
"font/roboto/Roboto-Medium.woff2",
"font/roboto/Roboto-Regular.ttf",
"font/roboto/Roboto-Regular.woff",
"font/roboto/Roboto-Regular.woff2",
"font/roboto/Roboto-Thin.ttf",
"font/roboto/Roboto-Thin.woff",
"font/roboto/Roboto-Thin.woff2",
"images/bkg.svg",
"images/clouds.svg",
"images/hills.svg",
"images/hills2.svg",
"images/moon.svg",
"images/snow.svg",
"images/snowDark.svg",
"images/sun.svg",
"images/github.svg",
"client.js",
"favicon.ico",
"icon_16.png",
"icon_32.png",
"icon_36.png",
"icon_64.png",
"icon_72.png",
"icon_96.png",
"icon_120.png",
"icon_128.png",
"icon_144.png",
"icon_152.png",
"icon_192.png",
"hammer.min.js",
"headroom.min.js",
"diff_match_patch/diff_match_patch.js",
"chrono.min.js",
"tinycolor-min.js",
"web-animations.min.js",
"parse-1.6.12.min.js",
"sjcl.js",
"index.html",
"style.css"
];
// Set the callback for the install step
self.addEventListener('install', function(event) {
// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
.then(function() {
self.clients.matchAll().then(function(all) {
all.map(function(client) {
client.postMessage({getCommit: true});
});
});
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});
self.addEventListener('activate', function(event) {
var cacheWhitelist = [CACHE_NAME];
console.log("deleting old caches");
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.map(function(cacheName) {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});