← Back to Tools

SW Cache Builder

Generate production-ready service worker scripts. Pick strategy, add assets, deploy.

FAST
Cache First
Serve from cache, fallback to network. Best for static assets (CSS, fonts, images).
FRESH
Network First
Try network, fallback to cache. Best for HTML pages and API calls.
BALANCED
Stale-While-Revalidate
Serve cache instantly, update in background. Best all-rounder for pages.
LIVE
Network Only
Always fetch fresh. Use for analytics, payments, real-time data.

Service Worker Caching — When & Why

A service worker acts as a programmable proxy between your site and the network. Once registered, it intercepts every request and can serve cached responses — making repeat visits near-instant and keeping your app alive even without a connection.

Cache First vs Network First

Use Cache First for assets that rarely change (fonts, images, CSS). Use Network First for HTML and API data where freshness matters. Wrong choice = stale content or unnecessary network requests.

When to bump the version

Change v1v2 any time you deploy new code. This triggers the SW to re-install with fresh assets. Without versioning, users may be stuck on old cached files for days.

Scope matters

A SW at /blog/sw.js can only control pages under /blog/. To control your whole site, place sw.js at the root and keep scope as /.

Background Sync

If a user submits a form offline, Background Sync queues the request and replays it when connectivity returns. Essential for PWAs targeting unreliable networks.