damage-calc
damage-calc copied to clipboard
Add offline support using ServiceWorker
An html5 service worker sounds easier to do, and it would provide offline access for all operating systems.
Here's an example, though you'll also need to make a manifest if you want to make it a web app (that the user can be prompted to install to their home screen, it'll run within their browser in offline mode when they tap the icon).
https://gist.github.com/Hidden50/3c62a415745f931385a0036ce1ad70c8
Originally posted by @Hidden50 in https://github.com/Zarel/honko-damagecalc/issues/191#issuecomment-390338501
http://guangcongluo.com/saber/service-worker.js
if (navigator.serviceWorker && !navigator.serviceWorker.controller) {
navigator.serviceWorker.register('service-worker.js', {
scope: './'
}).then(function (reg) {
console.log('Service worker registered: ' + reg.scope);
});
}
the main tradeoff is "if there's internet, do you serve the local file or download the newest version?" if you serve the local file, it loads instantly, but it might be old if you download the newest version, it's guaranteed to be the newest one, but it'll take longer to load
Originally posted by @Zarel on Discord
My link takes the "download the newest version" tradeoff, which I think you forgot to mention.
I also wrote a lot more on Discord, in case anyone was interested in the history of Service Workers:
[1:19 PM] Zarel: the main tradeoff is "if there's internet, do you serve the local file or download the newest version?"
[1:20 PM] Zarel: if you serve the local file, it loads instantly, but it might be old
[1:20 PM] Zarel: if you download the newest version, it's guaranteed to be the newest one, but it'll take longer to load
[1:20 PM] Zarel: this was a huge argument back in the original implementation of offline web apps
[1:21 PM] Zarel: that one served the local version so it would load instantly
[1:21 PM] Zarel: and if there was a newer version, you would have to show a message telling users to refresh, losing their work in some cases
[1:21 PM] Zarel: and so people would often be on old versions and report bugs that were already fixed and it would be a mess
[1:22 PM] Zarel: so we scrapped the entire thing and the new system is incredibly complex and uses service workers so you can decide which tradeoff you want
[1:23 PM] Zarel: and my apps use "download the newest version" because that's the least dumb one
https://developers.google.com/web/tools/workbox/modules/workbox-build