faysal0x1/service-worker-module

Reusable service worker + frontend cache module for Laravel (nwidart).

Installs: 7

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Language:JavaScript

Type:laravel-module

pkg:composer/faysal0x1/service-worker-module

1.0.3 2026-01-11 15:51 UTC

This package is not auto-updated.

Last update: 2026-01-12 01:22:16 UTC


README

Reusable nwidart/laravel-modules package that ships:

  • A production-ready sw.js implementation with image/API caching helpers
  • Frontend utilities (resources/js/utils/serviceWorker.js + config helper)
  • Publishable config files (config/service-worker.php, config/frontend-cache.php)
  • Documentation (SERVICE_WORKER_CONFIG.md)

Installation

composer require faysal0x1/service-worker-module
php artisan module:enable ServiceWorker

Publish assets

# Config + docs
php artisan vendor:publish --provider="App\Modules\ServiceWorker\Providers\ServiceWorkerServiceProvider" --tag=serviceworker-config
php artisan vendor:publish --provider="App\Modules\ServiceWorker\Providers\ServiceWorkerServiceProvider" --tag=serviceworker-docs

# Frontend helpers
php artisan vendor:publish --provider="App\Modules\ServiceWorker\Providers\ServiceWorkerServiceProvider" --tag=serviceworker-frontend

# Optional: publish the service worker bootstrap + standalone worker file
php artisan vendor:publish --provider="App\Modules\ServiceWorker\Providers\ServiceWorkerServiceProvider" --tag=serviceworker-assets

Frontend usage

import serviceWorkerManager from '@/utils/serviceWorker';

serviceWorkerManager.init(page.props);
serviceWorkerManager.register();

The manager automatically shares configuration via Inertia props and exposes helpers for clearing caches, pushing config updates, etc.

Service worker route

The module registers GET /service-worker-module/sw.js, which serves the worker code. The published public/sw.js bootstrap simply importScripts this route, so the worker always stays in sync with the module.