-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
46 lines (42 loc) · 1.24 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
'use strict';
const CACHE_NAME = 'kennzeichen';
const REQUIRED_FILES = [
'.',
'index.html',
'icon.png',
'style.css',
'script.js',
'manifest.json',
'data/kennzeichen.json',
'data/laenderkennzeichen.json',
'data/diplomatenkennzeichen.json'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME)
.then((cache) => {
console.log('[install] Caches opened, adding all core components to cache');
return cache.addAll(REQUIRED_FILES);
})
.then(() => {
console.log('[install] All required resources have been cached, we\'re good!');
return self.skipWaiting();
})
);
});
self.addEventListener('activate', (event) => {
event.waitUntil(self.clients.claim());
});
self.addEventListener('fetch', (event) => {
console.log('[fetch] Handling fetch event for:', event.request.url);
event.respondWith(
caches.match(event.request).then((response) => {
if (response) {
console.log('[fetch] Returning from ServiceWorker cache: ', event.request.url);
return response;
}
console.log('[fetch] Returning from server: ', event.request.url);
return fetch(event.request);
})
);
});