-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
executable file
·61 lines (55 loc) · 1.4 KB
/
sw.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
58
59
60
61
/*
*
* LPA
* Author: Ido Green
* Date: March 2016
*/
// Until all the browsers will give us the APIs to cache.
importScripts('/cache-polyfill.js');
var cacheName = "LPA-v3";
//
// Install our web app and its assets
//
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open(cacheName).then(function(cache) {
console.log("LPA is caching it's files under: " + cacheName);
return cache.addAll([
'/',
'/index.html',
'/index.html?homescreen=1',
'/?homescreen=1',
'css/bootstrap-theme.min.css',
'css/bootstrap.min.css',
'js/vendor/modernizr-2.8.3-respond-1.4.2.min.js',
'js/vendor/jquery-1.11.2.min.js',
'js/vendor/bootstrap.min.js'
]).then(function() {
return self.skipWaiting();
});
})
);
});
//
self.addEventListener('activate', function(e) {
console.log('[LPA SW] Activate');
e.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
console.log('[LPA SW] Removing old cache', key);
if (key !== cacheName) {
return caches.delete(key);
}
}));
})
);
});
//
self.addEventListener('fetch', function(event) {
console.log("SW got: " + event.request.url);
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});