-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
executable file
·74 lines (68 loc) · 2.53 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
71
72
73
74
const cacheName = 'KanbanWebPWA';
const pathname = '/KanbanWeb';
const filesToCache = [
pathname+'/',
pathname+'/sw.js',
pathname+'/style.css',
pathname+'/script.js',
pathname+'/modules/AVElement.js',
pathname+'/modules/AVutils.js',
pathname+'/App/App.js',
pathname+'/App/App.html',
pathname+'/App/App.css',
pathname+'/App/Menu/Menu.js',
pathname+'/App/Menu/Menu.html',
pathname+'/App/Menu/Menu.css',
pathname+'/App/Board/Board.js',
pathname+'/App/Board/Board.html',
pathname+'/App/Board/Board.css',
pathname+'/App/ControlPanel/Recyclebin/Recyclebin.js',
pathname+'/App/ControlPanel/Recyclebin/Recyclebin.html',
pathname+'/App/ControlPanel/Recyclebin/Recyclebin.css',
pathname+'/App/ControlPanel/ControlPanel.js',
pathname+'/App/ControlPanel/ControlPanel.html',
pathname+'/App/ControlPanel/ControlPanel.css',
pathname+'/App/Board/Stickynote/Stickynote.js',
pathname+'/App/Board/Stickynote/Stickynote.html',
pathname+'/App/Board/Stickynote/Stickynote.css',
pathname+'/App/Board/Stickynote/StickynoteOptions/StickynoteOptions.js',
pathname+'/App/Board/Stickynote/StickynoteOptions/StickynoteOptions.html',
pathname+'/App/Board/Stickynote/StickynoteOptions/StickynoteOptions.css',
pathname+'/App/Board/Stickynote/StickynoteOptions/ListSelector/ListSelector.js',
pathname+'/App/Board/Stickynote/StickynoteOptions/ListSelector/ListSelector.html',
pathname+'/App/Board/Stickynote/StickynoteOptions/ListSelector/ListSelector.css'
];
self.addEventListener("install", (event) => {
event.waitUntil(performInstalloperations());
});
self.addEventListener('activate', event => {
performActivationOperations();
});
self.addEventListener("fetch", (event) => {
event.respondWith(handleFetchRequisition(event));
});
async function performActivationOperations() {
let keyList = await caches.keys();
return Promise.all(
keyList.map(key => {
if (key !== cacheName) {
return caches.delete(key);
}
})
);
}
async function performInstalloperations() {
let clientCache = await caches.open(cacheName);
for (let fileToCache of filesToCache) {
await clientCache.add(fileToCache);
}
}
async function handleFetchRequisition(event) {
let response = await caches.match(event.request);
if(!response) {
response = await fetch(event.request);
let clientCache = await caches.open(cacheName);
clientCache.put(event.request, response.clone());
}
return response;
}