Service Worker Generator
Get a working service worker for a small site, with a cache strategy you choose and an offline fallback for page navigations.
Use the tool
Why this tool exists
List the files to precache, choose a cache version and a strategy for other same-origin GET requests, and the tool writes sw.js: an install step that caches your shell, an activate step that deletes old caches, the chosen fetch strategy and a fallback to your offline page when a navigation fails. A commented registration snippet is included.
Caching bugs can leave users on old files, so bump the cache version when assets change and test with the Application panel. Do not cache authenticated or personalised responses with a shared strategy.
No data is sent anywhere: the work happens in your browser, so you can use it offline once the page has loaded.
How to use it
- List the paths to precache, one per line.
- Pick a strategy and an offline fallback page.
- Save the output as /sw.js and register it from your page.
- Change the cache version whenever you deploy new assets.
Frequently asked questions
Which strategy should I pick?
Stale-while-revalidate suits most static assets; network-first suits HTML that changes often; cache-first suits versioned files that never change.
Why does my old version keep loading?
The previous service worker is serving cached files. Change the cache name and unregister it during development.
Does it handle POST requests or APIs?
No. Only same-origin GET requests are intercepted.
Is my data sent anywhere?
No. Everything is processed in your browser, and the page makes no network requests with your input.