Offline

https://web.dev/offline-cookbook/ - specific to Service Workers, but defines terms that are useful generally

  • Network-only
    • Always fetch the data and use it; no cache involved
    • (the easiest to implement)
  • Network falling back to cache
    • Try to load the data from network and cache it
    • If network fails, and if there’s cached data, return it
    • (Traditional browser default for server-rendered pages)
  • Stale-while-revalidate
    • If there’s a cached version, use it
    • Always fetch an update and store it
    • If there was not a cached version, use the updated version
    • (don’t see the update until next time)
  • Cache then network
    • If there is cached data, show it
    • Make a network request. If it returns, cache it and update the data to show it
    • (The Ember Data default)

Less frequently useful

  • Cache-only
    • Fetch the data initially and cache it
    • Only used the cached version; never refetch
  • Cache, falling back to network
    • Upon request, if the data is cached, use it and don’t refetch
    • Otherwise, fetch, cache, and return; never refetch
    • (never allows data to be updated)
  • Cache and network race
    • Try to load the data both from cache and network
    • Whichever returns with data first, use it
    • Cache what the network returns
    • (seems only useful in cases where disk access is slow)