-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
70 lines (65 loc) · 1.59 KB
/
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
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
var CACHE = 'cache-and-update';
var prefetchedURLs = [
'jquery-3.5.1.min.js',
'pouchdb.min.js',
'pouchdb.upsert.min.js',
'pdfkit.standalone.js',
'blob-stream.js',
'db.js',
'lib.js',
'sw.js',
'jquery.myTransposer.js',
'jquery.toTextarea.js',
'list.min.js',
'import.js',
'jszip.min.js',
'mark.min.js',
'notyf.min.js',
'pdfformatter.js',
'pouchdb.authentication.min.js',
'index.html',
'presentation.html',
'presentation.js',
'sortable.js',
'notyf.min.css',
'style.css',
'jquery.myTransposer.css',
'2html.css',
'apple-touch-icon.png',
'browserconfig.xml',
'favicon-mask.png',
'favicon.png',
'icon.png',
'icon512.png',
'manifest.webmanifest',
'mstile-150x150.png',
'safari-pinned-tab.svg'
];
self.addEventListener('install', function(evt) {
console.log('The service worker is being installed.');
evt.waitUntil(precache());
});
self.addEventListener('fetch', function(evt) {
console.log('The service worker is serving the asset.');
evt.respondWith(fromCache(evt.request));
evt.waitUntil(update(evt.request));
});
function precache() {
return caches.open(CACHE).then(function (cache) {
return cache.addAll(prefetchedURLs);
});
}
function fromCache(request) {
return caches.open(CACHE).then(function (cache) {
return cache.match(request).then(function (matching) {
return matching || fetch(request); //Promise.reject('no-match');
});
});
}
function update(request) {
return caches.open(CACHE).then(function (cache) {
return fetch(request).then(function (response) {
return cache.put(request, response);
});
});
}