📎 Webclip
How To Make Your PWA Offline On Demand
The article explains how the author’s PWA was made available offline on demand, using a Spotify- or Netflix-like model where users download content only when they ask for it. The implementation keeps the app editable offline and lets local changes be uploaded again when the user returns online.
Reading notes#
- The chosen approach makes the application’s content available offline only when requested, instead of keeping the whole app offline all the time.
- The offline flow starts by lazy-loading all slide content and assets before anything is cached or stored locally.
- Workbox is used in the service worker to cache images with separate strategies for regular and third-party sources.
- Deck data is saved locally in IndexedDB with the deck identifier as the storage key.
- A global offline state lets the app use an offline service or an online service without changing the higher layers of the application.
- When online, the app reads from Firestore; when offline, it reads from IndexedDB.
- App assets such as icons and fonts are listed in a JSON file and cached by calling the Service Worker from the app context.
- After caching is complete, the app switches to offline mode.
- The same architecture allows local content to remain editable while offline.
- When the user goes back online, the app uploads local content from IndexedDB and transfers local assets to remote storage.
