-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceWorker.js
37 lines (32 loc) · 1011 Bytes
/
serviceWorker.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
'use strict';
var CACHE_NAME = '1.0.2-dev12';
//cacheAll = true;
self.addEventListener('install', function(event) {
self.skipWaiting();
});
self.addEventListener('fetch', function(event) {
if(event.request.method !== 'GET' || event.request.url.match(/\/icos\/random/)) return;
event.respondWith(
caches.match(event.request).then(function(resp) {
return resp || fetch(event.request).then(function(response) {
//if(!(cacheAll)) return response;
return caches.open(CACHE_NAME).then(function(cache) {
cache.put(event.request, response.clone());
return response;
});
});
})
);
});
self.addEventListener('activate', function(event) {
var cacheWhitelist = [CACHE_NAME];
event.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (cacheWhitelist.indexOf(key) === -1) return caches.delete(key);
}));
}).then(function() {
self.clients.claim()
})
);
});