Add PWA files and service worker
This commit is contained in:
parent
83a2dae19f
commit
da4fe814c2
BIN
docs/icon-256.png
Normal file
BIN
docs/icon-256.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
|
@ -38,6 +38,18 @@
|
|||
transform: translate(-50%, 0%);
|
||||
}
|
||||
</style>
|
||||
<link rel="manifest" href="./manifest.json">
|
||||
<script>
|
||||
// register ServiceWorker
|
||||
window.onload = () => {
|
||||
'use strict';
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker
|
||||
.register('./sw.js');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
14
docs/manifest.json
Normal file
14
docs/manifest.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "Egui Template PWA",
|
||||
"short_name": "egui-template-pwa",
|
||||
"icons": [{
|
||||
"src": "./icon-256.png",
|
||||
"sizes": "256x256",
|
||||
"type": "image/png"
|
||||
}],
|
||||
"lang": "en-US",
|
||||
"start_url": "./index.html",
|
||||
"display": "standalone",
|
||||
"background_color": "white",
|
||||
"theme_color": "white"
|
||||
}
|
25
docs/sw.js
Normal file
25
docs/sw.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
var cacheName = 'egui-template-pwa';
|
||||
var filesToCache = [
|
||||
'./',
|
||||
'./index.html',
|
||||
'./egui_template_bg.wasm'
|
||||
];
|
||||
|
||||
|
||||
/* Start the service worker and cache all of the app's content */
|
||||
self.addEventListener('install', function(e) {
|
||||
e.waitUntil(
|
||||
caches.open(cacheName).then(function(cache) {
|
||||
return cache.addAll(filesToCache);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
/* Serve cached content when offline */
|
||||
self.addEventListener('fetch', function(e) {
|
||||
e.respondWith(
|
||||
caches.match(e.request).then(function(response) {
|
||||
return response || fetch(e.request);
|
||||
})
|
||||
);
|
||||
});
|
Loading…
Reference in a new issue