-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathservice-worker.js
executable file
·117 lines (108 loc) · 3.39 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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const CACHE_NAME = 'at-the-wall-cache';
const urlsToCache = [
'/',
'icons/icon-72x72.png',
'icons/icon-96x96.png',
'icons/icon-128x128.png',
'icons/icon-144x144.png',
'icons/icon-152x152.png',
'icons/icon-192x192.png',
'icons/icon-384x384.png',
'icons/icon-512x512.png',
'launch-screens/launch-screen-2048x2732.png',
'launch-screens/launch-screen-2732x2048.png',
'launch-screens/launch-screen-1668x2388.png',
'launch-screens/launch-screen-2388x1668.png',
'launch-screens/launch-screen-1668x2224.png',
'launch-screens/launch-screen-2224x1668.png',
'launch-screens/launch-screen-1536x2048.png',
'launch-screens/launch-screen-2048x1536.png',
'launch-screens/launch-screen-1536x2048.png',
'launch-screens/launch-screen-2048x1536.png',
'launch-screens/launch-screen-1242x2688.png',
'launch-screens/launch-screen-2688x1242.png',
'launch-screens/launch-screen-1125x2436.png',
'launch-screens/launch-screen-2436x1125.png',
'launch-screens/launch-screen-828x1792.png',
'launch-screens/launch-screen-1792x828.png',
'launch-screens/launch-screen-1125x2436.png',
'launch-screens/launch-screen-2436x1125.png',
'launch-screens/launch-screen-1242x2208.png',
'launch-screens/launch-screen-2208x1242.png',
'launch-screens/launch-screen-750x1334.png',
'launch-screens/launch-screen-1334x750.png',
'launch-screens/launch-screen-1242x2208.png',
'launch-screens/launch-screen-2208x1242.png',
'launch-screens/launch-screen-750x1334.png',
'launch-screens/launch-screen-1334x750.png',
'launch-screens/launch-screen-1242x2208.png',
'launch-screens/launch-screen-2208x1242.png',
'launch-screens/launch-screen-750x1334.png',
'launch-screens/launch-screen-1334x750.png',
'launch-screens/launch-screen-640x1136.png',
'launch-screens/launch-screen-1136x640.png',
'favicons/apple-touch-icon-57x57.png',
'favicons/apple-touch-icon-60x60.png',
'favicons/apple-touch-icon-72x72.png',
'favicons/apple-touch-icon-76x76.png',
'favicons/apple-touch-icon-114x114.png',
'favicons/apple-touch-icon-120x120.png',
'favicons/apple-touch-icon-144x144.png',
'favicons/apple-touch-icon-152x152.png',
'favicons/favicon-16x16.png',
'favicons/favicon-32x32.png',
'favicons/favicon-96x96.png',
'favicons/favicon-128x128.png',
'favicons/favicon-196x196.png',
'favicons/ms-tile-70x70.png',
'favicons/ms-tile-144x144.png',
'favicons/ms-tile-150x150.png',
'favicons/ms-tile-310x150.png',
'favicons/ms-tile-310x310.png',
'favicons/favicon.ico'
];
self.addEventListener('install', event => {
self.skipWaiting();
event.waitUntil(
caches.open(CACHE_NAME).then(cache => cache.addAll(urlsToCache))
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(response => {
if (response) {
return response;
}
const fetchRequest = event.request.clone();
return fetch(fetchRequest).then(response => {
if (
!response ||
response.status !== 200 ||
response.type !== 'basic'
) {
return response;
}
const responseToCache = response.clone();
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
cache.put(event.request, responseToCache);
})
);
return response;
});
})
);
});
self.addEventListener('activate', event => {
event.waitUntil(
caches
.keys()
.then(cacheNames =>
Promise.all(
cacheNames
.filter(cacheName => cacheName !== CACHE_NAME)
.map(cacheName => caches.delete(cacheName))
)
)
);
});