Kill switch
A broken service worker is worse than a broken server: it stays in browsers and keeps serving pages even after you fix the server. That is why the package can turn the service worker off on every device with a single command.
Usage
bash
php artisan pwa:disable # asks for confirmation; --force skips the question
php artisan pwa:enableWhat happens
- A flag is stored in the cache (
sw.kill_switch_store, otherwise the default store). No deployment needed. /sw.jsstarts returning a minimal service worker (resources/sw/kill-switch.js):- on install, it calls
skipWaiting(), - on activate, it deletes all
pwa-*caches, callsregistration.unregister()and reloads open windows from the network.
- on install, it calls
<x-pwa::head/>passesenabled: falseto the client; the client removes any registrations itself.- The manifest stays, and the installed app keeps working online.
The browser checks /sw.js on every navigation (updateViaCache: 'none', no-cache), so each device drops the service worker on its next visit.
Caveats
- Push subscriptions: unregistering the service worker cancels push subscriptions in browsers. The command warns you about this when
sw.importis set. Afterpwa:enable, users have to opt in to notifications again (your push system should restore the subscription onpwa:resume). - Multiple servers: the flag must live in shared storage (Redis, database, Memcached). With a
fileorarraystore, the command warns you. public/sw.js: if this file exists, the web server serves it instead of the route and the kill switch does not work.pwa:doctorreports this as an error.php artisan cache:cleardeletes the flag (it lives in the cache). After clearing the cache, checkphp artisan about(the Laravel PWA section → Kill switch).
Local development
With PWA_ENABLED=false (the default in local), /sw.js returns the same self-destroying service worker, so a service worker left over from earlier testing removes itself from your browser.