-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathservice-worker.js
35 lines (32 loc) · 1.03 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
const cacheName = 'tether_cache-v2';
const precacheResources = [
'/',
'/offline/',
'/404.html',
'/fonts/Quantico400.woff2',
'/fonts/Quantico700.woff2',
'/fonts/Tulpen-One400.woff2',
'/icons/favicon-16x16.png',
'/tether_theme.mp3',
'/libs/font-awesome.min.css',
'/libs/fontawesome-webfont.woff'
];
// When the service worker is installing, open the cache and add the precache resources to it
self.addEventListener('install', (event) => {
console.log('Service worker install event!');
event.waitUntil(caches.open(cacheName).then((cache) => cache.addAll(precacheResources)));
});
self.addEventListener('activate', (event) => {
console.log('Service worker activate event!');
});
// When there's an incoming fetch request, try and respond with a precached resource, otherwise fall back to the network
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((cachedResponse) => {
if (cachedResponse) {
return cachedResponse;
}
return fetch(event.request);
}),
);
});