fix(pwa): retirar service worker cache-first (servía código obsoleto y rompía POSTs)
El sw.js experimental (mayo) tenía tres problemas graves:
1. Estrategia cache-first para TODO: una vez cacheada una página o asset, el
navegador servía la versión vieja indefinidamente, incluso tras deploys
("los cambios no se ven"). También cacheaba HTML con tokens CSRF caducados.
2. cache.put() sobre peticiones POST (no soportado, TypeError) → interceptaba
y podía romper peticiones Livewire de forma intermitente.
3. Su precache incluía /css/app.css y /js/app.js, inexistentes con Vite →
"Failed to execute 'addAll' on 'Cache': Request failed" en cada instalación.
Se sustituye por un SW de auto-limpieza (kill switch): al actualizarse en el
navegador borra todos los caches, se desregistra y recarga las pestañas.
Los layouts siguen registrándolo para que los clientes con la PWA vieja se
limpien solos; más adelante podrá retirarse el registro por completo.
Suite 94 passing.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,13 +50,12 @@
|
||||
|
||||
@stack('scripts')
|
||||
@livewireScripts
|
||||
{{-- PWA retirada: el sw.js antiguo (cache-first) servía versiones obsoletas
|
||||
tras cada deploy y rompía POSTs. El sw.js actual es de auto-limpieza:
|
||||
se registra una última vez para borrar caches y desregistrarse. --}}
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/sw.js').then(function(registration) {
|
||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||
}).catch(function(err) {
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
});
|
||||
navigator.serviceWorker.register('/sw.js');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -109,14 +109,11 @@
|
||||
@stack('scripts')
|
||||
@livewireScripts
|
||||
<script>
|
||||
{{-- PWA retirada: sw.js ahora es de auto-limpieza (borra caches y se desregistra) --}}
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/sw.js').then(function(registration) {
|
||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||
}).catch(function(err) {
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
});
|
||||
navigator.serviceWorker.register('/sw.js');
|
||||
}
|
||||
|
||||
|
||||
// Mobile menu toggle
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const menuBtn = document.querySelector('[data-dropdown-toggle]');
|
||||
|
||||
Reference in New Issue
Block a user