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
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?
http://gph.is/2dhW35c
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
https://www.pwastats.com/
https://developers.google.com/web/showcase/2017/twitter
Not just offline…
Accès wi-fi à Gorakshep (5140m) by Jerome Bon, on Flickr <https://flic.kr/p/bDzjj5> (CC BY 2.0).
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).
Zero-latency access to
content & data
speed 3 by Monkieyes, on Flickr <https://flic.kr/p/PXPwK> (CC BY 2.0).
Offline, Online & ¯\_(
ツ)_/¯
June 13, 2018 / © 2018 IBM Corporation
The next
billion people
on the internet
the galaxy by tommy@chau, on Flickr <https://flic.kr/p/sbEHMt> (CC BY 2.0).
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
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
https://caniuse.com/#feat=serviceworkers
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).
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).
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).
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
https://caniuse.com/#search=indexdb
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
https://github.com/localForage/localForage
Sync is Hard
Technological devices designed by D3Images / Freepik <http://www.freepik.com/>.
June 13, 2018 / © 2018 IBM Corporation
Apache CouchDB PouchDB
IBM Cloudant
June 13, 2018 / © 2018 IBM Corporation
“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/
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
https://pouchdb.com/
Pokedex.org
An offline-capable Progressive Web App built with
Service Worker and PouchDB
https://www.pokedex.org/
June 13, 2018 / © 2018 IBM Corporation
Multi-User Apps with Hoodie
http://hood.ie/
June 13, 2018 / © 2018 IBM Corporation
June 13, 2018 / © 2018 IBM Corporation
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
Cloudant Envoy
June 13, 2018 / © 2018 IBM Corporation
June 13, 2018 / © 2018 IBM Corporation
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
https://github.com/ibm-watson-data-lab/shopping-list June 13, 2018 / © 2018 IBM Corporation
https://developer.ibm.com/code/patterns/create-an-offline-first-shopping-list-progressive-web-app/
June 13, 2018 / © 2018 IBM Corporation
Join the
Offline First
community
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
offlinefirst.org/chat
June 13, 2018 / © 2018 IBM Corporation
https://medium.com/offline-camp
Thank you
codait.org
twitter.com/BradleyHolt
medium.com/@BradleyHolt github.com/bradley-holt developer.ibm.com/code
June 13, 2018 / © 2018 IBM Corporation
June 13, 2018 / © 2018 IBM Corporation