A service worker is the small script that makes a WordPress site behave more like an app. It decides what loads when the connection drops, how fast repeat visits feel, and whether a visitor sees the page you published this morning or a copy from last week. Most guides stop at “it caches things.” The trouble lives in the rules it caches by.
This guide explains how a service worker for WordPress works: its lifecycle, where WordPress serves it from, which cache rules matter, how to inspect it in DevTools, and where it collides with page caches and security plugins. The examples use Progressify, DaftPlug’s PWA plugin, because we can show exactly what its worker does. The concepts apply to any setup.
What a service worker is, and what it is not
A service worker is a JavaScript file the browser runs in the background, separate from your pages. Once registered, it sees every request from the pages it controls and can answer from a cache, from the network, or both. That one ability makes offline pages, faster repeat visits, push and background sync possible.
A few properties explain most of its behavior:
- It is not part of the page. It cannot touch the page itself, and the browser can wake it with no tab open, which is how push arrives after the visitor leaves.
- It needs HTTPS. Browsers only register service workers in secure contexts.
localhostis treated as secure for testing, so a worker can run on your laptop and still fail on a staging site served over plain HTTP. - It is not the HTTP cache. The browser’s normal cache follows your
Cache-Controlheaders. A service worker keeps its own storage through the Cache API, and those headers have no say over what it stores. Clearing one does not clear the other. - It sits in front of everything else. It answers before the request ever reaches your page cache, your CDN or your server. That is why a bad cache rule in the worker can serve a stale page even after you purge every other cache.
The service worker lifecycle in plain words
Every service worker goes through the same stages. They explain the two common questions: “why is my change not showing?” and “why did the first visit not work offline?”
- Register. A page tells the browser where the script lives. If the download fails, the file is not valid JavaScript, or it throws an error, registration fails.
- Install. The browser runs the install step once per version of the script. This is where a worker usually stores the files it must have, such as an offline page.
- Wait. If an older version still controls open tabs, the new one waits until all of them close. A reload is not enough.
- Activate. The new version takes over and can delete old caches.
- Control. The page that registered the worker is not controlled until the next load, unless the worker calls
clients.claim(). - Update. The browser checks for a new version when the visitor navigates to a page in scope, and when events like push wake the worker, unless it already checked in the last 24 hours. If the file differs by even one byte, the new version starts the cycle again. If the new version fails to install, the browser throws it away and keeps the old one running.
Modern Chrome ignores normal HTTP cache headers when it checks for a new version of the worker script itself, so a long Cache-Control on that one file no longer traps visitors on an old worker for days.
How Progressify handles the lifecycle
Progressify’s generated worker calls skipWaiting() during install and clients.claim() during activation. In practice that removes the waiting stage: when you change an offline setting or update the plugin, the new worker takes over on the visitor’s next visit instead of waiting for every tab to close, and it starts controlling the open page without a second reload.
Each version also gets its own cache names, built from a checksum of the worker’s content plus the plugin version. When a new version activates, it deletes the older Progressify caches. So changing your caching strategy or expiration resets the stored copies on each visitor’s device the next time the browser picks up the new worker, which is usually their next visit.
Where WordPress serves the service worker, and why scope matters
Any service worker WordPress serves only controls pages inside its scope. By default the scope is the folder the script lives in. A worker at /wp-content/plugins/some-plugin/sw.js could only control URLs under that plugin folder, which is useless. To control the whole site, the script has to be served from the site root, or the server has to send a Service-Worker-Allowed header that permits a wider scope.
So Progressify serves its worker from your home URL with a query string:
https://example.com/?progressify_serviceworker=1
It sends the script as application/javascript with no-cache headers, an X-Robots-Tag: noindex, follow header so search engines skip it, and a Service-Worker-Allowed header set to your home path. The registration code runs after the page finishes loading and sets the scope to your home path, so a site at the domain root gets / and a site installed in a subfolder gets that subfolder. Progressify also builds the URL with a trailing slash so WordPress does not redirect it on subfolder installs, because registration fails when the script URL redirects.
Two rules follow from scope:
- One worker per scope. If two plugins register workers for the same scope, only one controls each page. A second PWA or offline plugin, or an old worker left behind by a plugin you removed, is the most common source of “my settings do nothing.”
- Push services need to share it. Progressify detects the OneSignal and Webpushr plugins and imports their worker code into its own, so push from those services and Progressify’s caching can live in one worker instead of fighting over the scope.
The worker file is also generated on disk under /wp-content/uploads/progressify/scripts/. If that file goes missing, for example after a migration that skipped uploads, version 1.5.2 rebuilds it on the next request.
The five caching strategies, briefly
A caching strategy is the rule the worker applies to each request. These five come from Workbox, the open source service worker library from the Chrome team that Progressify builds on. Progressify ships Workbox 7.3.0 inside the plugin instead of loading it from Google’s CDN, so the worker does not depend on a third party that is unreachable in some regions.
| Strategy | What the worker does | Typical fit |
|---|---|---|
| Network-First | Tries the network, stores the answer, uses the stored copy only when the network fails | Most WordPress sites, stores, news |
| Stale While Revalidate | Answers from the cache at once, then refreshes the copy in the background | Content where a slightly old copy is fine |
| Cache-First | Answers from the cache, goes to the network only when nothing is stored | Rarely changing sites |
| Network-Only | Never stores anything | Pages that must never be stale, no offline |
| Cache-Only | Only ever answers from the cache | Fixed content you control tightly |
In Progressify free, the worker always uses Network-First. Pro unlocks the other four in Progressify > Settings > Offline Usage. Network-First is the safe default: online visitors always get the current page, and the cached copy only appears when the network is gone.
Choosing one for a blog, store or membership site has real tradeoffs, covered in how to pick a browser cache strategy without serving stale pages. Here, the rules around the strategy matter more.
The cache rules that matter: expiration, limits and exclusions
The strategy says where an answer comes from. The rules say what gets stored, for how long, and what is never touched. In Progressify’s worker those rules are fixed in code, so you can reason about them exactly.
Two separate caches. Pages (HTML documents) go into a pages cache. Everything else the browser requests, such as CSS, scripts, images and fonts, goes into a resources cache. Splitting them means a burst of image requests cannot push your pages out.
Entry limits. The pages cache keeps up to 50 entries and the resources cache up to 30, dropping the oldest when full. A visitor who browsed 200 posts only has the most recent ones offline.
Expiration. Both caches use the Cache Expiration Time setting, which defaults to 10 days and accepts 1 to 10. One detail from the Workbox documentation is worth knowing: expiration is checked after a cached entry is used, so an expired entry can be served once before it is removed. If you use Cache-First on Pro, a short expiration of one or two days limits how long a visitor can be stuck on an old page.
What gets stored. Only successful responses are cached, meaning status 200, plus status 0, which is how browsers report cross-origin responses they cannot inspect. Error pages are not saved.
What is never cached. Requests to /wp-admin, the REST API under wp-json, and any URL containing preview=true always go to the network. Workbox also only routes GET requests by default, so form submissions and other POST requests pass through untouched.
The offline fallback. During install the worker stores an offline page. When a visitor asks for a page that is not in the cache and the network fails, they see that page instead of the browser’s error screen. Pro lets you replace it with your own page.
What about cart and checkout?
Progressify does not have a setting that excludes specific pages such as the cart or checkout from the service worker cache. The built-in exclusions are the admin, the REST API and previews. With Network-First, that is fine for a store: online shoppers always get a fresh cart, checkout and account page, and the cached copy only shows when they are offline. The risk appears if you switch a store to Cache-First or Cache-Only, so do not use those on WooCommerce. Developers who need extra rules can append code to the generated worker with the progressify_serviceworker filter, but a syntax error there breaks registration, which silently disables offline support, install prompts and push, so test it on staging first.
Debug your service worker in Chrome DevTools
Open your site in Chrome, open DevTools and go to the Application panel.
- Service Workers. You should see one worker for your site’s scope, marked as activated. For Progressify the Source URL ends in
?progressify_serviceworker=1. A red error count links to the Console. - Update on reload. Tick this while testing so the browser fetches a fresh worker on every load. Update forces a single check, and Unregister removes the worker for your browser only.
- Bypass for network. Sends every request to the network without going through the worker. If a bug disappears with this ticked, the worker is the cause.
- Offline. Simulates no connection. Visit a page you loaded before and it should appear from the cache. Visit one you never opened and you should see the offline page.
- Cache Storage. With Progressify you will see a pages cache and a resources cache, each ending in the current version code.
- Storage. Clear site data unregisters the worker and wipes its caches in one click. Use it to test the first visit experience again.
A Shift reload bypasses the worker for one load, and a private window starts with no worker and no caches, which makes it the cleanest first visit test.
Page cache and security plugin conflicts
Most service worker problems on WordPress are not in the worker. They come from something in front of it.
- Page caches and CDNs. A page cache that stores the worker URL as if it were a page can serve an old script, or serve HTML where JavaScript is expected. Exclude
?progressify_serviceworker=1and?progressify_manifest=1from your page cache and CDN rules, then purge. - Security and firewall plugins. Some block query string URLs they do not recognize, so the worker URL returns a 403 or a login page. Load the worker URL in a private window: you should see JavaScript. If you see HTML or an error, allowlist both Progressify URLs.
- Two plugins, one scope. Run one PWA or offline plugin at a time. Lightify, DaftPlug’s speed plugin, steps aside when Progressify is active and shows its browser cache as handled by Progressify, so the two do not run competing workers.
When testing a fix, clear caches from the outside in: CDN, page cache, then the worker.
If the worker never appears in DevTools at all, that is a registration problem rather than a caching one.
What a service worker does not do
- It does not speed up the first visit. It installs after the first page loads, so benefits start on the next view.
- It does not replace your page cache or CDN. It stores copies on one device. Your server still answers new visitors and every Network-First request.
- It does not make your whole site work offline. It only has what each visitor already viewed, within the limits above.
- It does not run on plain HTTP, except on
localhost. - It does not fix a slow server. With Network-First, online visitors wait for your server as usual. Navigation preload, which Progressify enables when the browser supports it, lets that request start while the worker boots, so the worker adds as little delay as possible, but it cannot make the server faster.
- It does not install your app on its own. Installability depends on the manifest, icons, HTTPS and the browser. Chrome no longer requires a service worker for installing from the menu.
Service worker for WordPress FAQ
Do I need to write a service worker myself? No. Progressify generates the worker from your settings, serves it from your home URL and regenerates it when you save. Code is only needed for custom rules through the progressify_serviceworker filter.
Will a service worker show visitors old content after I publish? With Network-First, no: online visitors get the current page and the cached copy only appears offline. With Cache-First or Cache-Only, yes, until the copy expires, which is why those strategies are risky for sites that change often.
Does the service worker cache logged-in or admin pages? The admin, REST API and previews always go to the network in Progressify’s worker. Other front end pages follow your strategy, so keep Network-First if logged-in visitors see personalized pages.
Is a service worker free in Progressify? Yes. The free plugin includes the worker, offline caching with Network-First, the expiration setting and the offline page. Pro adds the other four strategies, a custom offline page, an offline notice and background sync, as part of the DaftPlug membership. Plans cover 1, 5 or 100 sites, starting at $37.99 a year, with a 14-day money-back guarantee.


