forked from chiqden/180-stereo-photo-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
48 lines (44 loc) · 1.51 KB
/
service-worker.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
const APP_NAME = '180-stereo-photo-viewer';
const VERSION = '1.3.2';
const CACHE_NAME = `${APP_NAME}-cache-v${VERSION}`;
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
return cache.addAll([
'./',
'./index.html',
'./scripts/exif-js-v2.3.0-added-support-for-extended-xmp.js',
'./scripts/180-stereo-photo-viewer.js',
'./scripts/offline-support.js',
'https://aframe.io/releases/1.5.0/aframe.min.js',
'https://cdn.aframe.io/fonts/Roboto-msdf.json',
'https://cdn.aframe.io/fonts/Roboto-msdf.png'
]
);
})
);
});
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys()
.then(cacheNames => {
return Promise.all(cacheNames.map(cacheName => {
if (cacheName.startsWith(APP_NAME) && cacheName !== CACHE_NAME) {
return caches.delete(cacheName);
}
}));
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
if (response) {
return response;
}
return fetch(event.request);
})
);
});