forked from cdevroe/unmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
45 lines (42 loc) · 1.23 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
var CACHE_NAME = 'unmark-version-1.9.2';
var urlsToCache = [
'/assets/css/unmark.css',
'/assets/libraries/jquery/jquery-2.1.0.min.js',
'/custom/assets/js/production/unmark.loggedin.js',
'/assets/js/plugins/modernizr-2.7.1.min.js',
'/assets/js/production/unmark.plugins.js'
];
self.addEventListener('install', function(event) {
self.skipWaiting();
console.log('Service Worker: Installed');
// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Service Worker: Opened cache');
return cache.addAll(urlsToCache);
})
);
});
// Call Activate Event
self.addEventListener('activate', e => {
console.log('Service Worker: Activated');
// Remove unwanted caches
e.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cache => {
if (cache !== CACHE_NAME) {
console.log('Service Worker: Clearing Old Cache ' + cache);
return caches.delete(cache);
}
})
);
})
);
});
// Call Fetch Event
self.addEventListener('fetch', e => {
console.log('Service Worker: Fetching ' + e.request);
e.respondWith(fetch(e.request).catch(() => caches.match(e.request)));
});