WhoBuilt

Offline Strategies In React Native

Oct 9, 2019· 22 min· 8.4K views·Watch on YouTube

Speaker

Chiamaka Nwolisa, a front-end engineer at Ghanaian health tech company mPharma, shares offline-first strategies for React Native and React at React Native EU 2019 in Wrocław.

Why offline matters

Nwolisa argues that reliable connectivity is an unsafe assumption: users move between fast networks and no connection. She cites a figure that about 45% of connected devices have speeds at or below 2 Mbps, and demonstrates that downloading a 14 MB file at that speed takes about 43 seconds.

Cache data and fetch it in layers

Offline apps need local persistence, but deciding when cached data is stale is the harder problem. Nwolisa suggests using timestamps and overwriting cached data rather than deleting it, so users can see stale information instead of nothing. Her repository pattern checks memory, then disk, then network, saving network results to disk and memory for later use.

Communicate offline status and sync changes

Clear connection messages help users understand what is available offline; Nwolisa points to Gmail, Coursera, and YouTube as examples and mentions React Native NetInfo for detecting connection changes. Read intensive apps mainly display data, while write intensive apps also need a way to preserve and sync user-created changes. She describes CouchDB replication and, for existing systems, a change log with incremental sync and exponential backoff for failures.

Make content available without a connection

Nwolisa describes a radio app that let users download recorded shows after they reported slow playback and breaks in recordings. Downloads made listening smoother and available offline. She also recommends image caching, including React Native Fast Image, which wraps Glide on Android and SDWebImage on iOS.

Design the useful offline experience

Nwolisa closes with three principles: communicate clearly, use local data where possible, and offer downloads. She emphasizes that the right offline experience depends on the app and its users, based on her work building three offline applications.

Takeaways

  • Treat network access as unreliable and decide what users should still be able to do without it.
  • Use timestamps to judge cache freshness, and retain stale data when it is more useful than an empty screen.
  • Fetch through memory, disk, and network in order, persisting network responses for future offline use.
  • For apps with offline edits, record changes, sync only what changed, and plan for failed sync attempts.
  • Let users download useful content and clearly explain when some features need a connection.

Mentioned in this talk

Search inside this talk

What was claimed 11

  • feature
    mPharma: Health technology company headquartered in Ghana, on a mission to provide quality health care and affordable medicine to everyone in Africa
    “mPharma is a health tech company headquartered in Ghana”
    YouTube
    Unverified1 source· Talk
  • role at
    Chiamaka Nwolisa is front-end engineer at mPharma
    “I'm a front-end engineer at mPharma.”
    YouTube
    Unverified1 source· Talk
  • feature
    CouchDB replication protocol: Syncs JSON documents between client and server, server and server, or client and client peers
    “Two peers could be client and server, server and server, or client and client.”
    YouTube
    Unverified1 source· Talk
  • feature
    Couchbase Lite: Brings the CouchDB API to the client
    “Couchbase Lite ... brings the CouchDB API to the client”
    YouTube
    Unverified1 source· Talk
  • feature
    PouchDB: Brings the CouchDB API to the client
    “PouchDB ... brings the CouchDB API to the client”
    YouTube
    Unverified1 source· Talk
  • feature
    CouchDB: Replication protocol syncs JSON documents between two peers
    “it uses what it calls the replication protocol to sync JSON documents between two peers”
    YouTube
    Unverified1 source· Talk
  • uses
    “Redux Offline ... uses this under the hood as well.”
    YouTube
    Unverified1 source· Talk
  • feature
    Trello: Mobile app is offline-first and can be used without an internet connection
    “The Trello mobile app is offline-first, so you can use it fluently without an internet connection.”
    YouTube
    Unverified1 source· Talk
  • feature
    FastImage: Drop-in replacement for React Native's Image component that can cache remote images
    “It's also a drop-in replacement for the Image component bundled with React Native”
    YouTube
    Unverified1 source· Talk
  • integrates with
    FastImage integrates with SDWebImage
    “and SDWebImage for iOS”
    YouTube
    Unverified1 source· Talk
  • integrates with
    FastImage integrates with Glide
    “It wraps Glide for Android”
    YouTube
    Unverified1 source· Talk

Related talks