Skip to content

Instantly share code, notes, and snippets.

@mornir
Last active April 5, 2018 16:34
Show Gist options
  • Save mornir/c8ff28cc5c7049f5f13cdbf827030eec to your computer and use it in GitHub Desktop.
Save mornir/c8ff28cc5c7049f5f13cdbf827030eec to your computer and use it in GitHub Desktop.
Caching Strategies

Cache with Network Fallback

Fist try to access then cache, if it fails reach for the network.

Cache only

Only access the cache... usually not a good strategy

Network only

Only access the network... usually not a good strategy but can be useful for assets that never changes

Network with Cache Fallback

Fist try to access then network, if it fails reach for the cache. Problem: if the network connection is bad, it can take some time before it succeed or failed, and in the meantime we don't serve our cached assets.

Cache then Network

  1. Page reaches directly for the cache (not via service worker) AND Service Worker reach out to the network
  2. optional but recommended: service worker dynamically cache assets fetched from network
  3. service worker return fetched assets to the page

Workbox

staleWhileRevalidate

cache then network with dynamic caching

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment