add service worker

This commit is contained in:
Ricardo (XenGi) Band 2025-07-22 16:03:20 +02:00
commit 3d2fbd4e3e
No known key found for this signature in database
4 changed files with 29 additions and 0 deletions

BIN
img/icon-192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
img/icon-512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 KiB

View file

@ -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
View 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);
})
);
});