There are DBs for that: CouchDB (https://couchdb.apache.org/) (with its browser counterpart, PouchDB), Gun (https://github.com/amark/gun) and probably others.
I wish there was some easy to use library to solve this problem as this seems to be a problem many people come across when building a PWA.
Re:How to make a web app work offline
by feistypharit on Sunday March 08, 2020 @08:27AM
(#22517685)
Checkout workbox.
Workbox is about service workers. So for very simple stuff like caching assets, it is quite helpful, but I was referring to the more transactional actions like multiple clients writing to the same backend, requiring to resolve conflicts.
To my knowledge workbox doesn't help with that.
Why does your app hijack the back button? (Firefox macOS)
It's a single-page-app, so it uses the history API to route between paths. Unfortunately, there's a bug in my implementation (which I haven't been able to nail down yet), which causes the back button not to work consistently on all paths.
Re:How to make a web app work offline
by gkfasdfasdf on Sunday March 08, 2020 @08:59AM
(#22517795)
Google's Firestore API allows data to be persisted locally and synced.
I did a bunch of work to make one of my hobby projects (https://pitchy.ninja) work off-line. The trickiest part was data synchronization between IndexedDB and the database on the server, managing and resolving conflicts if the app was used on multiple devices offline at the same time (then went online again.)
Although IndexedDB worked pretty well in the end, it is a very finicky database, with a really convoluted API. There's a whole bunch of corner cases that you need to handle, and some of these are non-obvious.