PHPackages                             jeffersongoncalves/laravel-pwa-service-worker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jeffersongoncalves/laravel-pwa-service-worker

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jeffersongoncalves/laravel-pwa-service-worker
=============================================

A Laravel package that serves a PWA service worker at /sw.js from a Blade template whose cache version tracks the Vite build manifest hash. Ships precache + cache-first (hashed assets), network-first (navigations) and stale-while-revalidate (everything else) strategies with an offline fallback, all configurable.

v1.1.0(1mo ago)250MITPHP ^8.2

Since Jun 22Compare

[ Source](https://github.com/jeffersongoncalves/laravel-pwa-service-worker)[ Packagist](https://packagist.org/packages/jeffersongoncalves/laravel-pwa-service-worker)[ Docs](https://github.com/jeffersongoncalves/laravel-pwa-service-worker)[ GitHub Sponsors](https://github.com/jeffersongoncalves)[ RSS](/packages/jeffersongoncalves-laravel-pwa-service-worker/feed)WikiDiscussions Synced 2w ago

READMEChangelog (2)Dependencies (20)Versions (3)Used By (0)

[![Laravel PWA Service Worker](https://raw.githubusercontent.com/jeffersongoncalves/laravel-pwa-service-worker/master/art/jeffersongoncalves-laravel-pwa-service-worker.png)](https://raw.githubusercontent.com/jeffersongoncalves/laravel-pwa-service-worker/master/art/jeffersongoncalves-laravel-pwa-service-worker.png)

Laravel PWA Service Worker
==========================

[](#laravel-pwa-service-worker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f630217b31114482b2bb967f39deef68710b82d0bbf8f42f57fbfe0375145490/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d7077612d736572766963652d776f726b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jeffersongoncalves/laravel-pwa-service-worker)[![GitHub Tests Action Status](https://camo.githubusercontent.com/4d65afd5b6c364207688d020e121f9a1a48ad7fde3cddaa9dad59eb64831ed1a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d7077612d736572766963652d776f726b65722f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/jeffersongoncalves/laravel-pwa-service-worker/actions?query=workflow%3Arun-tests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/7ecf86a5c704e5ef66b42abfaeb9565f2e139f0bc7d7bc613ef32c78a671b412/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d7077612d736572766963652d776f726b65722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/jeffersongoncalves/laravel-pwa-service-worker/actions?query=workflow%3A%22Fix+PHP+code+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/317b0a35ad60c14d9b3355d9602c5caf5475230c6ae8732df8bcc15eaa5d7c6d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d7077612d736572766963652d776f726b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jeffersongoncalves/laravel-pwa-service-worker)

Serve a production-ready PWA service worker at `/sw.js`, rendered from a Blade template whose cache version tracks the Vite build manifest hash — so a `npm run build` automatically busts the SW cache without you editing the worker.

Ships three caching strategies out of the box:

- **cache-first** for content-hashed `/build/*` assets (immutable, safe to cache forever)
- **network-first** for HTML navigations (fresh when online, cached + offline fallback when not)
- **stale-while-revalidate** for everything else (images, fonts, …)

…plus precache on install, old-cache teardown on activate, and a `pwa-updated` `postMessage` so your front-end can show an "update available" toast.

Installation
------------

[](#installation)

```
composer require jeffersongoncalves/laravel-pwa-service-worker
```

The `/sw.js` route is registered automatically. Register the service worker from your layout:

```

  if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('/sw.js');
  }

```

Optionally publish the config and view:

```
php artisan vendor:publish --tag="pwa-service-worker-config"
php artisan vendor:publish --tag="pwa-service-worker-views"
```

Update notifications
--------------------

[](#update-notifications)

When a new worker activates it `postMessage`s `{ type: 'pwa-updated', version }` to every controlled page. Listen for it to surface an "update available" prompt and reload once the user accepts:

```

  if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('/sw.js');

    let reloading = false;

    navigator.serviceWorker.addEventListener('message', (event) => {
      if (event.data?.type !== 'pwa-updated') {
        return;
      }

      // First install fires this too; only prompt when a worker was already
      // in control (i.e. this is a genuine upgrade, not the initial load).
      if (!navigator.serviceWorker.controller) {
        return;
      }

      if (window.confirm('A new version is available. Reload now?')) {
        window.location.reload();
      }
    });

    // Guard against reload loops if the SW takes control mid-session.
    navigator.serviceWorker.addEventListener('controllerchange', () => {
      if (reloading) {
        return;
      }
      reloading = true;
    });
  }

```

Offline fallback
----------------

[](#offline-fallback)

The worker serves `config('pwa-service-worker.offline_url')` (default `/offline`) for a failed navigation when nothing is cached. **You** register that route — it is intentionally not provided, since the offline page is app-specific:

```
Route::view('/offline', 'offline')->name('pwa.offline');
```

Configuration
-------------

[](#configuration)

KeyDefaultDescription`enabled``true`Register the `/sw.js` route.`path``sw.js`Route path (keep at root for a `/` scope).`middleware``[]`Extra middleware applied to the `/sw.js` route (e.g. a security-headers middleware).`view``pwa-service-worker::sw`Blade view rendered as the worker body.`build_manifest``public/build/manifest.json`md5 seeds the cache version.`cache_prefix``pwa`Cache name is `{prefix}-v{version}`.`offline_url``/offline`Fallback for failed navigations.`precache_urls``['/offline', '/']`Seeded on install.`passthrough_prefixes``['/admin', '/livewire', '/api', …]`Always hit the network.`passthrough_exact``['/sw.js', '/manifest.json']`Always hit the network (exact path).`asset_prefix``/build/`Content-hashed assets served cache-first.Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance90

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

45d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/411493?v=4)[Jefferson Gonçalves](/maintainers/jeffersongoncalves)[@jeffersongoncalves](https://github.com/jeffersongoncalves)

---

Tags

laraveljeffersongoncalveslaravel-pwa-service-worker

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jeffersongoncalves-laravel-pwa-service-worker/health.svg)

```
[![Health](https://phpackages.com/badges/jeffersongoncalves-laravel-pwa-service-worker/health.svg)](https://phpackages.com/packages/jeffersongoncalves-laravel-pwa-service-worker)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.4M352](/packages/psalm-plugin-laravel)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

78727.1M206](/packages/laravel-mcp)[api-platform/laravel

API Platform support for Laravel

58174.6k18](/packages/api-platform-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

817336.8k3](/packages/defstudio-telegraph)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1239.7k25](/packages/fleetbase-core-api)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

24773.9k](/packages/harris21-laravel-fuse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
