add service worker
This commit is contained in:
parent
1c2bab4491
commit
3d2fbd4e3e
4 changed files with 29 additions and 0 deletions
BIN
img/icon-192.png
Normal file
BIN
img/icon-192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
BIN
img/icon-512.png
Normal file
BIN
img/icon-512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 279 KiB |
|
|
@ -254,3 +254,8 @@ validatePurpose(document.querySelector("#purpose input"));
|
|||
|
||||
// generate qr code on first visit
|
||||
regenerate();
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/js/service-worker.js');
|
||||
}
|
||||
|
||||
|
|
|
|||
24
js/service-worker.js
Normal file
24
js/service-worker.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
self.addEventListener('install', event => {
|
||||
event.waitUntil(
|
||||
caches.open('app-cache').then(cache => {
|
||||
return cache.addAll([
|
||||
'/',
|
||||
'/index.html',
|
||||
'/css/bulma.min.css',
|
||||
'/js/index.js',
|
||||
'/js/qr-creator.min.js',
|
||||
'/img/icon-192.png',
|
||||
'/img/icon-512.png'
|
||||
]);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
event.respondWith(
|
||||
caches.match(event.request).then(response => {
|
||||
return response || fetch(event.request);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Loading…
Reference in a new issue