mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 00:39:26 +00:00
PWA support attempt 1 #20
This commit is contained in:
27
webassets/manifest.webmanifest
Normal file
27
webassets/manifest.webmanifest
Normal file
@@ -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"
|
||||
}
|
||||
42
webassets/service-worker.js
Normal file
42
webassets/service-worker.js
Normal file
@@ -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
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user