Free Tool

Service Worker Strategy Builder

Generate a production-ready Service Worker powered by Workbox. Choose your caching strategies for HTML, assets, and images, and download your file instantly.

Frequent questions

What is a Service Worker?

A Service Worker is a JavaScript file that runs separately from the main browser thread. It intercepts network requests, allowing you to cache assets locally, serve offline fallback pages, and handle background synchronization or push notifications. It is the core technology that makes a Progressive Web App (PWA) work offline.

What is the "Network First" strategy?

Network First attempts to fetch the latest resource from the network. If the network request fails (e.g., the user is offline), it falls back to a previously cached version. This is highly recommended for HTML pages so users always see the most up-to-date content when connected.

What is the "Stale While Revalidate" strategy?

This strategy instantly serves a resource from the cache for maximum speed, but simultaneously fires off a background network request to update the cache for the *next* time the user visits. It's perfect for CSS and JavaScript files.

What is the "Cache First" strategy?

Cache First looks for the resource in the cache and serves it immediately. It only goes to the network if the resource isn't cached yet. This saves a massive amount of bandwidth and is the ideal strategy for static assets like images and web fonts that rarely change.

How do I register the generated sw.js file?

Place the downloaded sw.js file in the root directory of your website. Then, paste this registration script into your main HTML file, right before the closing </body> tag: <script> if ('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/sw.js'); }); } </script>

Why does this use Workbox?

Workbox is a set of libraries developed by Google that makes writing Service Workers incredibly easy. Writing vanilla Service Worker caching logic from scratch is prone to edge-case bugs. Workbox abstracts the hard parts (like cache expiration and routing) into clean, readable code.

Can I add Push Notifications with this generator?

Push notifications require managing subscription keys, databases, and backend server logic, which cannot be done entirely in a static sw.js file. However, with the full version of Progressier, push notifications and background sync are handled for you automatically without writing any code. Sign up to add complete push functionality to your PWA.

Your app here

Looking for a more complete solution?

With Progressier, abstract your service worker and create a fully-featured PWA without code.

Generate PWA See plans