-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcache.js
57 lines (55 loc) · 1.49 KB
/
cache.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
// all URLs will be added to cache
const cacheAssets = assets => {
return new Promise((res, reject) => {
// open cache
caches.open('assets')
.then(cache => {
// use cache API
cache.addAll(assets)
.then(() => {
console.log('All assets added to cache! Now ready for offline use.')
res()
})
.catch(err => {
console.log('Error while syncing assets. Offline use may not work as expected.', err)
reject()
})
}).catch(err => {
console.log('Cache error try reloading to reopen cache.', err)
reject()
})
})
}
// list of URLs to be cached
var assets = [
'./index.html',
'./pit.html',
'./favicon.ico',
'./resources/css/normalize.css',
'./resources/css/scoutingPASS.css',
'./resources/images/field_location_key.png',
'./resources/js/easy.qrcode.min.js',
'./resources/js/googleSheets.js',
'./resources/js/scoutingPASS.js',
'./resources/js/TBAInterface.js',
'./serviceWorker.js',
'./site.webmanifest',
'./cache.js',
'./process/index.css',
'./process/index.html',
'./process/index.js',
'./2023/CU_config.js',
'./2023/CU_Pit_config.js',
'./2023/field_image.png',
'./2023/grid_image_alt.png',
'./2023/grid_image.png',
'./android-chrome-192x192.png',
'./android-chrome-512x512.png',
'./favicon-32x32.png',
'./favicon-16x16.png'
]
// cache responses of provided URLs
cacheAssets(assets)
.then(() => {
console.log('Cache sync complete')
})