-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
44 lines (40 loc) · 1.06 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
var appCacheName = 'DSMapp-cache-v0.1';
var filesToCache = [
'/',
'/index.html',
'/style.css',
'js/app.js',
'js/jquery-3.2.1.min.js',
'js/jquery.transit.js',
'tips/index.html',
'about/index.html',
];
// Add selected files to cache
self.addEventListener( 'install', function( event ) {
event.waitUntil(
caches.open( appCacheName )
.then( function( cache ) {
return cache.addAll(filesToCache);
}))
});
// Update cache content if it no longer matches key `appCacheName`
self.addEventListener('activate', function( e ) {
e.waitUntil(
caches.keys().then( function( keyList ) {
return Promise.all( keyList.map( function( key ) {
if ( key !== appCacheName ) {
return caches.delete( key );
}
}));
})
);
return self.clients.claim();
});
// Serve cached resource if available, get it if not
self.addEventListener( 'fetch', function( e ) {
e.respondWith(
caches.match( e.request ).then( function( response ) {
return response || fetch(e.request);
} )
);
} );