Fog of War
Declarative offline for LiveView
LiveView is great.
Offline is also great.
Fog of War is an approach to fairly easy offline
which can work for a wide variety of apps.
Fog of War is offline support via simple caching
Fog of War is an idiom from old Real-Time Strategy games.
Like an explored part of a game map, it shows what was there
the last time you looked! Specifically, if you're offline, it
shows the last markup that the LiveView for that screen loaded with.
Unvisited screens are still unavailable, but you can style links
to them gracefully. And, you can even create a bundle of important
screens to 'pre-explore' the map, which is useful for mobile, where
the first experience might be an offline one.
LiveView is Great
LiveView is great. Most apps that do something
interesting are online, and have non-trivial server code.
And LiveView is the best way to make interesting apps.
But you used to be forced to split the program
up. For instance, when they pick a username, and you
automatically check to see if that name's
available as they're typing, you
need a separate little program, running in the browser.
Not a big deal at first, but you wouldn't believe
just how fragmented programs ended up.
Especially from about 2010-2020. Eventually, billion-dollar
startups were created whose sole reason to exist
was, basically, to paper this over that mess.
So, LiveView is great. No split brain, and you can drive any
complex client-side behavior you want from the server.
Offline is great
If you care about the user experience, and especially if you
want to wrap it in a mobile app, you need to think about offline behavior.
(There are those who will say that, if you care about
the user experience, you cannot possibly use web technologies
extensively in a mobile application. They are not usually saying it
because they believe it to be strictly true, but for other reasons).
If you install an app from an App Store, and then open it offline,
it is reasonable to expect that it shows a user a screen that is
ready to use, not a spinner. This is even true if that screen
requires you to sign in or sign up, and that
step will not work because you're offline.
Sure, some screens in an app require being online.
Showing a list of vacation rentals, for instance! But
much navigation should still be possible even when offline.
The creator of the app knows what screens make sense to
have cached and available for navigation locally, and which
ones need to be grayed out, or show some other graceful offline indication.