-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
74 lines (71 loc) · 2.38 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
62
63
64
65
66
67
68
69
70
71
72
73
74
var CACHE_STATIC_NAME = 'static-v4';
var CACHE_DYNAMIC_NAME = 'dynamic-v2';
self.addEventListener('install', function (event) {
console.log('[Service Worker] Installing Service Worker ...', event);
event.waitUntil(
caches.open(CACHE_STATIC_NAME)
.then(function (cache) {
console.log('[Service Worker] Precaching App Shell');
cache.addAll([
'/',
'/index.html',
'/form.html',
'/style.css',
'/style1.css',
'/js/animframe_polyfill.js',
'/js/application.js',
'/js/bind_polyfill.js',
'/js/classlist_polyfill.js',
'/js/game_manager.js',
'/js/grid.js',
'/js/html_actuator.js',
'/js/keyboard_input_manager.js',
'/js/local_storage_manager.js',
'/js/tile.js',
'/apple-touch-icon.png',
'/promise.js',
'/fetch.js',
'/insert.php',
'/register.js',
'https://fonts.googleapis.com/css?family=Montserrat',
]);
})
)
});
//comments
self.addEventListener('activate', function (event) {
console.log('[Service Worker] Activating Service Worker ....', event);
event.waitUntil(
caches.keys()
.then(function (keyList) {
return Promise.all(keyList.map(function (key) {
if (key !== CACHE_STATIC_NAME && key !== CACHE_DYNAMIC_NAME) {
console.log('[Service Worker] Removing old cache.', key);
return caches.delete(key);
}
}));
})
);
return self.clients.claim();
});
self.addEventListener('fetch', function (event) {
event.respondWith(
caches.match(event.request)
.then(function (response) {
if (response) {
return response;
} else {
return fetch(event.request)
.then(function (res) {
return caches.open(CACHE_DYNAMIC_NAME)
.then(function (cache) {
cache.put(event.request.url, res.clone());
return res;
})
})
.catch(function (err) {
});
}
})
);
});