Pro Yearly is on sale from $80 to $50! »

Offline Sync for Progressive Web Apps at O'Reilly Fluent

Offline Sync for Progressive Web Apps at O'Reilly Fluent

With the introduction of progressive web apps and browser APIs such as persistent storage, payments, geolocation, and push notifications, it is now possible to build fully featured mobile apps on the web platform. One important aspect of progressive web apps is the concept of building your app to be offline first. With an offline-first approach, you design your app for the most resource-constrained environment first. This approach provides a consistent user experience whether the user’s device has no connectivity, limited connectivity, or great connectivity.

The Service Worker API can do most of the heavy lifting when it comes to storing content and assets for offline-first progressive web apps. A bigger challenge can be storing and syncing your app’s data. One of the best answers today for offline sync for progressive web apps is a combination of Apache CouchDB (an open source document database), Hoodie (an open source Node.js backend for offline-first apps), and PouchDB (an open source JavaScript database that syncs). This stack can provide you with the starting point for your own progressive web app mobile backend and frontend, and it’s entirely open source.

Bradley Holt demonstrates how service workers, Apache CouchDB, Hoodie, and PouchDB can be used to build progressive web apps using an offline-first approach in order to provide fast, zero-latency access to content and data stored directly on the device.

8896271ee9d6f46d4b1783c9566cb645?s=128

Bradley Holt

June 13, 2018
Tweet

Transcript

  1. Offline Sync for Progressive Web Apps Bradley Holt Program Manager,

    Developer Advocacy Center for Open-Source Data and AI Technologies June 13, 2018 / © 2018 IBM Corporation
  2. None
  3. iPhone 4 - Bottom View with Bumper by William Hook,

    on Flickr <https://flic.kr/p/8e7p2s> (CC BY-SA 2.0). Web or mobile app?
  4. http://gph.is/2dhW35c

  5. Progressive Web Apps Provides both the discoverability of a web

    app and the reliable, fast, and engaging user experience of a native mobile app June 13, 2018 / © 2018 IBM Corporation
  6. https://www.pwastats.com/

  7. https://developers.google.com/web/showcase/2017/twitter

  8. None
  9. Not just offline… Accès wi-fi à Gorakshep (5140m) by Jerome

    Bon, on Flickr <https://flic.kr/p/bDzjj5> (CC BY 2.0).
  10. Reliable, fast, and engaging user experience— regardless of network connectivity

    Static Wallpaper by James Spinks, on Flickr <https://flic.kr/p/2b1JP> (CC BY-SA 2.0).
  11. Zero-latency access to content & data speed 3 by Monkieyes,

    on Flickr <https://flic.kr/p/PXPwK> (CC BY 2.0).
  12. Offline, Online & ¯\_(ツ)_/¯ June 13, 2018 / © 2018

    IBM Corporation
  13. The next billion people on the internet the galaxy by

    tommy@chau, on Flickr <https://flic.kr/p/sbEHMt> (CC BY 2.0).
  14. Geolocation API Network Information API IndexedDB WebRTC API Push API

    Notifications API Device Orientation API Screen Orientation API Permissions API Proximity API Pointer Lock API Vibration API Payment Request API Battery Status API Ambient Light Sensor API Service Worker API IBM Design Icons by International Business Machines Corporation <https://www.ibm.com/design/language/resources/icon-library/> (CC BY 4.0). June 13, 2018 / © 2018 IBM Corporation
  15. Service Workers Service Workers allow for fine- grained control over

    caching of content and assets, enabling cache-first web apps Service Workers fetch diagram by Mozilla Contributors <https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers> (CC-BY-SA 2.5). June 13, 2018 / © 2018 IBM Corporation
  16. https://caniuse.com/#feat=serviceworkers

  17. Registering a service worker example by Mozilla Contributors <https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers> (CC-BY-SA

    2.5).
  18. Install and activate a service worker example by Mozilla Contributors

    <https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers> (CC-BY-SA 2.5).
  19. Custom service worker response example by Mozilla Contributors <https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers> (CC-BY-SA

    2.5).
  20. IndexedDB IndexedDB enables app data to be stored locally within

    a browser IBM Design Icons by International Business Machines Corporation <https://www.ibm.com/design/language/resources/icon-library/> (CC BY 4.0). June 13, 2018 / © 2018 IBM Corporation
  21. https://caniuse.com/#search=indexdb

  22. localForage localForage wraps IndexedDB, WebSQL, or localStorage, providing a consistent

    API regardless of which storage mechanism is supported by the end user’s browser IBM Design Icons by International Business Machines Corporation <https://www.ibm.com/design/language/resources/icon-library/> (CC BY 4.0). June 13, 2018 / © 2018 IBM Corporation
  23. https://github.com/localForage/localForage

  24. Sync is Hard Technological devices designed by D3Images / Freepik

    <http://www.freepik.com/>. June 13, 2018 / © 2018 IBM Corporation
  25. None
  26. Apache CouchDB PouchDB IBM Cloudant June 13, 2018 / ©

    2018 IBM Corporation
  27. “CouchDB’s superpower is sync. Sometimes I even try to explain

    it to people by saying, ‘CouchDB isn’t a database; it’s a sync engine.’ It’s a way of efficiently transferring data from one place to another, while intelligently managing conflicts and revisions. It’s very similar to Git. When I make that analogy, the light bulb often goes off.” Nolan Lawson PouchDB & CouchDB: An interview with Nolan Lawson June 13, 2018 / © 2018 IBM Corporation https://blog.couchdb.org/2017/04/04/pouchdb-couchdb-an-interview-with-nolan-lawson/
  28. Offline Sync for Progressive Web Apps PouchDB Devices by Darwin

    Laganzon, on Pixabay <https://pixabay.com/photo-1917227/> (CC0 Public Domain). | Cloud by Raphael Silva, on Pixabay <https://pixabay.com/photo-2109664/> (CC0 Public Domain). June 13, 2018 / © 2018 IBM Corporation Apache CouchDB
  29. https://pouchdb.com/

  30. Pokedex.org An offline-capable Progressive Web App built with Service Worker

    and PouchDB https://www.pokedex.org/ June 13, 2018 / © 2018 IBM Corporation
  31. Multi-User Apps with Hoodie http://hood.ie/ June 13, 2018 / ©

    2018 IBM Corporation
  32. June 13, 2018 / © 2018 IBM Corporation

  33. Devices by Darwin Laganzon, on Pixabay <https://pixabay.com/photo-1917227/> (CC0 Public Domain).

    | Cloud by Raphael Silva, on Pixabay <https://pixabay.com/photo-2109664/> (CC0 Public Domain). PouchDB June 13, 2018 / © 2018 IBM Corporation Apache CouchDB
  34. Cloudant Envoy June 13, 2018 / © 2018 IBM Corporation

  35. June 13, 2018 / © 2018 IBM Corporation

  36. Shopping List A series of Offline First demo apps— each

    built using a different stack https://ibm-watson-data-lab.github.io/shopping-list-demo June 13, 2018 / © 2018 IBM Corporation
  37. https://github.com/ibm-watson-data-lab/shopping-list June 13, 2018 / © 2018 IBM Corporation

  38. https://developer.ibm.com/code/patterns/create-an-offline-first-shopping-list-progressive-web-app/ June 13, 2018 / © 2018 IBM Corporation

  39. Join the Offline First community

  40. Offline Camp We are building an Offline First community, one

    campfire at a time. Offline Camp has visited the Catskills of New York, the Central Coast of California, Berlin, and Oregon. June 13, 2018 / © 2018 IBM Corporation
  41. offlinefirst.org/chat June 13, 2018 / © 2018 IBM Corporation

  42. None
  43. https://medium.com/offline-camp

  44. Thank you codait.org twitter.com/BradleyHolt medium.com/@BradleyHolt github.com/bradley-holt developer.ibm.com/code June 13, 2018

    / © 2018 IBM Corporation
  45. June 13, 2018 / © 2018 IBM Corporation