diff --git a/webassets/manifest.webmanifest b/webassets/manifest.webmanifest new file mode 100644 index 0000000..4fa3434 --- /dev/null +++ b/webassets/manifest.webmanifest @@ -0,0 +1,27 @@ +{ + "dir": "ltr", + "lang": "English", + "name": "Spothole", + "short_name": "Spothole", + "scope": "/", + "display": "standalone", + "start_url": "https://spothole.m0trt.radio/", + "background_color": "white", + "theme_color": "white", + "description": "An Amateur Radio spotting tool bringing together DX clusters and outdoor programmes, providing a universal JSON API and web interface.", + "related_applications": [], + "prefer_related_applications": false, + "icons": [ + { + "src": "/img/icon-192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "/img/icon-512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "url": "https://spothole.m0trt.radio" +} diff --git a/webassets/service-worker.js b/webassets/service-worker.js new file mode 100644 index 0000000..520f8c2 --- /dev/null +++ b/webassets/service-worker.js @@ -0,0 +1,42 @@ +const CACHE_NAME = 'Spothole'; +const CACHE_URLS = [ + 'index.html', + './', + 'apidocs', + 'apidocs/openapi.yml', + 'about', + 'css/style.css', + 'js/code.js', + 'img/logo.png', + 'img/favicon.ico', + 'img/icon-32.png', + 'img/icon-192.png', + 'img/icon-512.png', + 'fa/css/fontawesome.min.css', + 'fa/css/solid.min.css', + 'fa/webfonts/fa-solid-900.ttf', + 'fa/webfonts/fa-solid-900.woff2' +]; + +self.addEventListener('fetch', (event) => { + // Is this an asset we can cache? + const url = new URL(event.request.url); + const isCacheableRequest = CACHE_URLS.includes(url.pathname); + + if (isCacheableRequest) { + // Open the cache + event.respondWith(caches.open(CACHE_NAME).then((cache) => { + // Go to the network first, cacheing the response + return fetch(event.request.url).then((fetchedResponse) => { + cache.put(event.request, fetchedResponse.clone()); + + return fetchedResponse; + }).catch(() => { + // If the network is unavailable, get from cache. + return cache.match(event.request.url); + }); + })); + } else { + // Not a cacheable request, must be a call to the API, so no cache involved just go to the network + } +});