feat: Phase 5.3 - PWA Offline Support with Workbox
Code Style & Quality / Laravel Pint (push) Waiting to run
Code Style & Quality / PHPStan Static Analysis (push) Waiting to run
Code Style & Quality / Test Suite (push) Waiting to run
Code Style & Quality / Browser Tests (Dusk) (push) Waiting to run

- Add vite-plugin-pwa + workbox-window
- Configure PWA manifest with icons (SVG)
- Configure Workbox runtime caching:
  - API routes: NetworkFirst (10s timeout, 100 entries, 24h)
  - Media files: CacheFirst (50 entries, 7 days)
  - Pages: NetworkFirst (10s timeout, 50 entries, 24h)
- Register service worker in app.js with update notification
- Generate icons (SVG) for all sizes

Tests: 101 passing (319 assertions)
This commit is contained in:
Javier Braña
2026-09-01 14:00:14 +02:00
parent 55b1a9276a
commit 356c4773fc
12 changed files with 4637 additions and 33 deletions
+25
View File
@@ -14,6 +14,31 @@ window.Echo = new Echo({
enabledTransports: ['ws', 'wss'],
});
// Register service worker for PWA
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then(registration => {
console.log('SW registered:', registration.scope);
registration.addEventListener('updatefound', () => {
const newWorker = registration.installing;
newWorker.addEventListener('statechange', () => {
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
console.log('New version available!');
if (confirm('Hay una nueva versión disponible. ¿Recargar?')) {
window.location.reload();
}
}
});
});
})
.catch(error => {
console.log('SW registration failed:', error);
});
});
}
import localforage from 'localforage';
// Generic function to queue any offline action