Service Worker
The SW is served at /sw.js as dynamic PHP output (registered via a rewrite rule). This allows PHP to inject config values without a build step.
Caching Strategies
| Strategy | Behavior |
|---|---|
| Network First | Network → cache fallback (good for HTML) |
| Cache First | Cache → network fallback (good for versioned assets) |
| Stale While Revalidate | Return cache immediately, update in background |
| Network Only | Always network (WooCommerce checkout/cart) |
| Cache Only | Always cache (precached assets only) |
Default strategy assignment
| Asset type | Setting key | Default |
|---|---|---|
| HTML pages | strategy_pages | network-first |
| Static assets (JS/CSS) | strategy_static | cache-first |
| Images | strategy_images | cache-first |
| Fonts | strategy_fonts | cache-first |
Custom URL Routing
In Service Worker → Custom Routes, add URL patterns with custom strategy overrides:
Pattern: /api/* Strategy: network-only
Pattern: /blog/* Strategy: stale-while-revalidate
Pattern: /wp-content/* Strategy: cache-first
Patterns support * wildcards and are matched against the request URL.
Precache
List of URLs to cache on SW install. Default includes the home page and critical static assets. Add custom URLs in Service Worker → Precache List.
Offline Fallback
Set an offline fallback page in Offline tab. When the network fails and no cache entry exists, the SW serves this page instead of a browser error.
