feat: Phase 5.3 - PWA Offline Support with Workbox
- 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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user