-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_offline_sw.js
More file actions
51 lines (46 loc) · 1.16 KB
/
app_offline_sw.js
File metadata and controls
51 lines (46 loc) · 1.16 KB
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
const CACHE_VERSION = 'motor-control-client-v1';
const URLS_TO_CACHE = [
'./',
'./css/main.css',
'./img/motor_icon_192.png',
'./img/motor_icon_512.png',
'./img/settings_icon.svg',
'./js/api_logic.js',
'./js/jquery-3.7.1.min.js',
'./js/keypad_logic.js',
'./js/settings.js',
'./js/signed_in_worker.js',
'./js/signin_state.js',
'./js/state_manager.js',
'./app_offline_sw.js',
'./index.html',
'./manifest.webmanifest'
];
self.addEventListener('install', event => {
console.log('Installing SW, caching: ', URLS_TO_CACHE)
event.waitUntil(
caches.open(CACHE_VERSION)
.then(cache => cache.addAll(URLS_TO_CACHE))
);
});
self.addEventListener('fetch', event => {
console.log('Fetching: ', event.request.url);
event.respondWith(
caches.match(event.request)
.then(response => response || fetch(event.request))
);
});
// handle updates
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cache => {
if (cache !== CACHE_VERSION) {
return caches.delete(cache);
}
})
);
})
);
});