Repository navigation
fix(sw): network-first y no cachear errores - #32
Merged
Merged
Conversation
El service worker servía primero la caché (los cambios de /data y del código llegaban con una carga de retraso, y JS nuevo podía mezclarse con JS viejo), guardaba cualquier respuesta incluidos 404/500, y silenciaba los fallos del precache. Además, sin red la app no llegaba a arrancar. - Mismo origen: network-first con timeout de 4 s; tras un timeout, 15 s sirviendo de caché directamente para no sumar un timeout por nivel (HTML → JS → JSON). Un error del servidor con copia en caché sirve la copia; sin copia, el error llega a la app. - Otros orígenes (Google Fonts): cache-first. - Solo se cachean respuestas ok (u opacas de otros orígenes). - Precache fichero a fichero con console.warn del que falle. - CACHE_NAME → v4 para purgar las cachés con 404 guardados. tests/sw.test.mjs comprueba que ASSETS existe, cubre todo js/, el CSS, los HTML, el manifest y sus iconos. Documentado en README (publicar cambios) y CONTRIBUTING (cuándo subir CACHE_NAME). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Qué cambia y por qué
El service worker tenía cuatro problemas:
/data(y en el código) se veían con una carga de retraso, y unapp.jsnuevo podía juntarse con unshared.jsviejo. Elcache: "no-store"defetchJSONno servía de nada.addAll(...).catch(() => {})), que además es todo o nada.Nueva estrategia (
service-worker.js)/data): network-first. Con conexión siempre llega lo último publicado. La caché se usa solo si no hay red o si la red tarda más de 4 s. Tras un timeout, durante 15 s se sirve directamente de caché, sin dejar de actualizarla en segundo plano, para que la cadena HTML → JS → JSON no sume un timeout por nivel.ok(u opacas, solo de otros orígenes).console.warndel que falle; el resto sí se guarda.CACHE_NAME→dinner-match-v4, para purgar cachés antiguas con 404 guardados.Versionado (criterio de la issue): con network-first ya no hace falta subir
CACHE_NAMEpara publicar cambios.CONTRIBUTING.mdexplica cuándo sí: al renombrar o borrar ficheros del shell, o al cambiar la estrategia. Lo prefiero a un hash automático, que exigiría un build step.tests/sw.test.mjs(en CI) comprueba que:ASSETSexisten;js/*.js, el CSS, los HTML, el manifest y sus iconos están precacheados (si no, la app no arranca offline en la primera visita).Docs: README ("Publicar cambios de contenido o de código"), CONTRIBUTING ("Service worker y caché") y CHANGELOG.
Rama base
developIssue relacionada
Closes #5
Pruebas
node --test: 51/51.localhost), contra un servidor que simula fallos:developdish-types.jsonvisible en la primera recargadata/types/*no se cachea; con el servidor arreglado, Reintentar entra a la primera* En el E2E, con el SW viejo el 404 no llegó a quedarse en caché a tiempo para afectar al reintento, pero el código lo guardaba igualmente (
cache.putsin comprobarok).Checklist
node --testpasa (y la CI está en verde)js/shared.js🤖 Generated with Claude Code