DocsoPWA6. Service Worker Caching Strategies
Reference

6. Service Worker Caching Strategies

oPWAorravo.com/docs/opwa/6-service-worker-caching-strategies

The SW is generated server-side by OPWA_SW_Builder::build() and served at /sw.js with Content-Type: application/javascript.

Strategy descriptions

StrategyBehaviourBest for
network-firstTry network; fall back to cache on errorHTML pages, dynamic content
cache-firstServe from cache; update in backgroundCSS, JS, fonts, images
stale-while-revalidateServe stale cache immediately; fetch update for next timeFrequently-changing assets where slightly stale is OK
network-onlyNever cache; always require networkCheckout, authentication, payments
cache-onlyOnly serve from cache; never networkPre-cached, locked assets

Cache names

CacheName pattern
Pagesopwa-pages-v{sw_version}
Static (JS/CSS)opwa-static-v{sw_version}
Imagesopwa-images-v{sw_version}
Offlineopwa-offline-v{sw_version}
Precacheopwa-precache-v{sw_version}

Cache names are versioned. Bumping sw_version causes the old caches to be deleted on the next SW activate event.

Cache expiry

Each strategy supports maxAge (seconds) and maxEntries. On a cache hit, the SW checks the Date header of the stored response. If older than maxAge, the cached entry is deleted and the request falls through to the network.


6. Service Worker Caching Strategies — oPWA Docs — Orravo