How to make a PWA work offline

Register a fetch event listener in your Service Worker to intercept network requests and dynamically cache the responses.

Offline Logo
  1. Pre-cache Core Assets: Use the Service Worker's install event to save essential files so the app shell always loads.
  2. Intercept Network Requests: Add a fetch event listener to catch every HTTP request the browser makes.
  3. Serve via Strategies: Use caches.match() to check for local files first, only using the network if the cache misses.
  4. Cache Dynamically: Clone valid network responses and save them using cache.put() for future offline access.

API

navigator.serviceWorker
window.caches

Code

Links & Documentation

Your app here

Ready to generate your PWA?

Try our PWA toolkit free of charge and without limits for 14 days. No credit card required.

Generate PWA See plans