How this blog manages OfflineFirst
You may not realise this, but this site is at least partially accessible offline. Visitors have to have been here before, and be using an internet browser which supports a technology called ServiceWorkers. If that is true, then you can still visit whilst offline and access content that you've already accessed.
Internet. Flaky. Never
For many of us in the west, connectivity is often spoken about like something we expect from the products and users we service. As the richest, we don't give too much thought to how those not as fortunate experience connectivity.
Even in the west, our connectivity, although assumed to be constant, is really in a perpetual state of flux. In 2017 whilst visiting Cornwall with my wife, the power to the whole house went out. With it the router. I had not experienced a power-loss in nearly 30 years. It was a surreal experience.
So what?
It might be that this never affects you, or your customers in the sense of being offline. I've had people within 50 miles phone me because their software was unreachable, who were using AWS. It still stopped them dead.
If that is inconceivable, imagine instead that for every visitor to your website, you had to pay a penny. With ServiceWorker technology and OfflineFirst approaches, you potentially save money on bandwidth, in the same way a cache works, but with explicit control. You can even (if you wanted) serve offline versions of pages.
The last benefit is in having something cool. As a technologist, I'll take the trade-off to serve more content, but also the learning experience. This month alone I saved any visitors to this blog around 300KB if they only visited a single page. In-fact the ServiceWorker this blog uses is HTTP status aware. If I delete a page, it deletes it from your cache. If there is a server error, then if the page was in your cache, it will be served, or the offline fallback served.
Interested?
Check out these links
- OfflineFirst online community
- IndieWeb wiki Offline
- IndieWeb wiki OfflineFirst
- Google caching files using ServiceWorker
- MDN Docs - ServiceWorker API
- MDN Docs - Cache API
- MDN Docs - Online & Offline browser events
Known problems?
Some things I would ask you to consider with ServiceWorker approach to OfflineFirst technologies.
- Only able to cache GET requests
- It's easy to get wrong
- There are storage limits
- Consider impact of resources from other sites
TTFN