Offline features is something that PWAs excel at. For Elixir LiveView, which is the most exciting web application technology I'm aware of in recent history, offline features are, perhaps, an anti-goal. But does it have to be that way?
The high-level workflow I could imagine LiveView supporting is based on the naive claim that liveview "just" keeps track of a datablob, i.e., the socket.assigns
. I'm imagining a cache_assigns: true
somewhere (maybe on the LiveSocket
js lib) that would "simply" cache the blob and on reconnect (maybe via an internal server-side event setup) would read the blob and incorporate the diff. There's then a handoff to the arbitrary client-side when offline. Something along the lines of, "the backend's last state is in local storage; do as you see fit; when the backend reconnects it'll read it in".
It's probably a silly idea because the edge cases of when to trust the blob, how to not use it when online, how to merge it with backend changes while it was offline, what constitutes allowable client-side manipulations, etc., is just overwhelming, at least as I think about it now. It's fun to think about, in the least.
I think when it comes to offline-first PWA web apps, the thing I'm trying to figure out is: how "clean" is the interop. I haven't looked into it enough to have opinions/conclusions/etc.
Resources
- ElixirForum Post: Offline Support for LiveView Features
- ElixirScript Elixir to Javascript tool
- Lumen An alternative BEAM implementation targeting WebAssembly
- Fly.io Blog Post: Saving and Restoring LiveView State This article is a great read to start with when exploring offline capabilities for LiveView.