-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
91 lines (84 loc) · 3.02 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var currVersion = '07_04_2020__01_37_00'
// Responde a mensagem de atualização de SW
self.addEventListener("message", function(event) {
if (event.data.action === "skipWaiting") {
self.skipWaiting();
}
});
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(currVersion).then(function(cache) {
return cache.addAll([
'./',
'index.html',
'favicon.ico',
'manifest.json',
'sw.js',
'swreg.js',
'vendor/fontawesome-free/css/all.min.css',
'https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i',
'css/sb-admin-2.min.css',
'css/sb-fupmobile.css',
'app/codemirror-5.52.2/lib/codemirror.js',
'app/codemirror-5.52.2/lib/codemirror.css',
'app/codemirror-5.52.2/mode/javascript/javascript.js',
'app/codemirror-5.52.2/theme/dracula.css',
'app/codemirror-5.52.2/addon/edit/closebrackets.js',
'app/codemirror-5.52.2/addon/hint/show-hint.js',
'app/codemirror-5.52.2/addon/hint/javascript-hint.js',
'vendor/jquery/jquery.min.js',
'vendor/bootstrap/js/bootstrap.bundle.min.js',
'vendor/jquery-easing/jquery.easing.min.js',
'js/sb-admin-2.min.js',
'app/jshint.js',
'app/editor.js',
'app/app.js',
'app/icons/icon-72x72.png',
'app/icons/icon-96x96.png',
'app/icons/icon-128x128.png',
'app/icons/icon-144x144.png',
'app/icons/icon-152x152.png',
'app/icons/icon-192x192.png',
'app/icons/icon-384x384.png',
'app/icons/icon-512x512.png',
'app/codemirror-5.52.2/addon/lint/lint.css',
'app/codemirror-5.52.2/addon/lint/lint.js',
'js/mine-js-lint.js'
]);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(caches.match(event.request).then(function(response) {
// caches.match() always resolves
// but in case of success response will have value
if (response !== undefined) {
return response;
} else {
return fetch(event.request).then(function (response) {
// response may be used only once
// we need to save clone to put one copy in cache
// and serve second one
let responseClone = response.clone();
caches.open(currVersion).then(function (cache) {
cache.put(event.request, responseClone);
});
return response;
}).catch(function () {
return caches.match('/sw-test/gallery/myLittleVader.jpg');
});
}
}));
});
this.addEventListener('activate', function(event) {
var cacheWhitelist = [currVersion];
event.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (cacheWhitelist.indexOf(key) === -1) {
return caches.delete(key);
}
}));
})
);
});