kopia lustrzana https://github.com/openstreetmap-polska/aed-mapa
Prepare web to PWA installable app.
Application is ready to use as offline app with caching requests.pull/48/head
rodzic
d3252b391a
commit
d90f24a0c4
|
@ -132,3 +132,6 @@ dmypy.json
|
|||
# IDE folders
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
# IIS configuration file
|
||||
web.config
|
||||
|
|
12
index.html
12
index.html
|
@ -199,6 +199,18 @@
|
|||
<path fill="currentColor" d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" />
|
||||
</svg>
|
||||
</button>
|
||||
<script>
|
||||
if ('serviceWorker' in navigator){
|
||||
window.addEventListener('load', () =>{
|
||||
navigator.serviceWorker.register('serviceWorker.js')
|
||||
.then(reg => {
|
||||
console.log('SW registred', reg);
|
||||
}).catch(err => {
|
||||
console.log('SW registration faild!', err);
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script src="./src/other-ui-stuff.js"></script>
|
||||
<script src="./src/map.js"></script>
|
||||
<script src="./src/osm-integration.js"></script>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
const cacheName = 'aed-map';
|
||||
const resToPrecache = [
|
||||
'/',
|
||||
'/index.html',
|
||||
'/src/css/main.css'
|
||||
];
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
console.log('SW install event!');
|
||||
event.waitUntil(
|
||||
caches.open(cacheName)
|
||||
.then(cache => {
|
||||
return cache.addAll(resToPrecache);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
console.log('SW now ready to handle fetches!');
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
console.log('SW fetch: ' + event.request.url);
|
||||
event.respondWith(
|
||||
caches.match(event.request).then((resp) => {
|
||||
return resp || fetch(event.request).then((response) => {
|
||||
return caches.open(cacheName).then((cache) => {
|
||||
cache.put(event.request, response.clone());
|
||||
return response;
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
|
@ -1,20 +1,28 @@
|
|||
{
|
||||
"name": "AED Mapa",
|
||||
"short_name": "AED Mapa",
|
||||
"start_url": "/",
|
||||
"start_url": "/index.html",
|
||||
"icons": [
|
||||
{
|
||||
"src": "./src/favicon/android-chrome-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
"type": "image/png",
|
||||
"purpose": "any maskable"
|
||||
},
|
||||
{
|
||||
"src": "./src/favicon/android-chrome-256x256.png",
|
||||
"sizes": "256x256",
|
||||
"type": "image/png"
|
||||
"type": "image/png",
|
||||
"purpose": "any maskable"
|
||||
},
|
||||
{
|
||||
"src": "./src/favicon/android-chrome-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "any maskable"
|
||||
}
|
||||
],
|
||||
"theme_color": "#008855",
|
||||
"background_color": "#f5f5f5",
|
||||
"display": "standalone"
|
||||
"display": "fullscreen"
|
||||
}
|
||||
|
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 45 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 3.6 KiB |
Ładowanie…
Reference in New Issue