Service worker for offline usage w/ workbox (https://developer.chrome.com/docs/workbox/modules/workbox-cli; https://github.com/openscad/openscad-playground/issues/56)
This commit is contained in:
parent
7b99679fb6
commit
af98f19850
3 changed files with 43 additions and 5 deletions
|
|
@ -32,7 +32,32 @@ if (process.env.NODE_ENV !== 'production') {
|
|||
declare var BrowserFS: BrowserFSInterface
|
||||
|
||||
|
||||
(async () => {
|
||||
|
||||
window.addEventListener('load', async () => {
|
||||
//*
|
||||
if ('serviceWorker' in navigator) {
|
||||
try {
|
||||
const registration = await navigator.serviceWorker.register('./sw.js');
|
||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker) {
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed' && navigator.serviceWorker.controller) {
|
||||
// Reload to activate the service worker and apply caching
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
} catch (err) {
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
}
|
||||
}
|
||||
//*/
|
||||
|
||||
registerCustomAppHeightCSSProperty();
|
||||
|
||||
const fs = await createEditorFS({prefix: '/', allowPersistence: isInStandaloneMode});
|
||||
|
|
@ -73,6 +98,6 @@ declare var BrowserFS: BrowserFSInterface
|
|||
<App initialState={initialState} statePersister={statePersister} fs={fs} />
|
||||
</React.StrictMode>
|
||||
);
|
||||
})();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue