kopia lustrzana https://github.com/FacilMap/facilmap
Add service worker to allow installing as a PWA
rodzic
12b8e737bd
commit
68b43bec32
|
@ -44,6 +44,9 @@ $(document).on("click", "a", function() {
|
|||
}
|
||||
});
|
||||
|
||||
if ('serviceWorker' in navigator)
|
||||
navigator.serviceWorker.register('./sw.js');
|
||||
|
||||
const queryParams = decodeQueryString(location.search);
|
||||
const toBoolean = (val: string, def: boolean) => (val == null ? def : val != "0" && val != "false" && val != "no");
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
// For now we just add offline support for index.html so that FacilMap can be installed as a PWA
|
||||
|
||||
const version = "v1";
|
||||
|
||||
self.addEventListener('install', (e) => {
|
||||
e.waitUntil(caches.open(version).then((cache) => cache.addAll(["/"])));
|
||||
});
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((keyList) => {
|
||||
return Promise.all(keyList.map((key) => {
|
||||
if(key != version)
|
||||
return caches.delete(key);
|
||||
}));
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
event.respondWith(caches.open(version).then((cache) => {
|
||||
return fetch(event.request).catch(() => {
|
||||
return cache.match(event.request, { ignoreSearch: true });
|
||||
});
|
||||
}));
|
||||
});
|
|
@ -136,6 +136,7 @@ module.exports = (env: any, argv: any): Configuration[] => {
|
|||
"favicon.ico",
|
||||
"favicon.svg",
|
||||
"manifest.json",
|
||||
"sw.js",
|
||||
"opensearch.xml"
|
||||
].map((file) => ({ from: `${__dirname}/static/${file}` }))
|
||||
}),
|
||||
|
|
Ładowanie…
Reference in New Issue