Files
localesp/public/sw.js
T
edgar.friendly 257fb9c622
deploy-branch / deploy (push) Successful in 2m36s
deploy-branch / teardown (push) Skipped
refactor(ui): modulariza App.jsx y unifica branding y caché PWA
- Extrae App.jsx en módulos reutilizables: constants/ (categorias,
  provincias), utils/geo, styles/shared, hooks/usePwaInstall y
  components/ (StarRating, LocalCard, CampoUbicacion, BannerMovil,
  CategoriaBadge)
- AdminPanel reutiliza constantes y componentes compartidos y corrige
  la limpieza de suscripciones de Firebase al desmontar
- Añade logos de marca (logo-localesp.png + @2x) y regenera los iconos
  PWA con tamaños menores
- sw.js: sube la caché del shell a v2 e incluye los nuevos iconos y logos
2026-08-05 19:07:00 +02:00

57 lines
1.4 KiB
JavaScript

const CACHE_NAME = "localesp-shell-v2";
const SHELL_ASSETS = [
"/",
"/manifest.webmanifest",
"/icon-192.png",
"/icon-512.png",
"/icon-512-maskable.png",
"/apple-touch-icon.png",
"/favicon-32.png",
"/logo-localesp.png",
"/logo-localesp@2x.png",
];
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(SHELL_ASSETS))
);
self.skipWaiting();
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
)
);
self.clients.claim();
});
// Network-first para la API (los datos deben estar frescos); cache-first
// para el resto del shell estático, para que la app abra offline.
self.addEventListener("fetch", (event) => {
const url = new URL(event.request.url);
if (event.request.method !== "GET") return;
if (url.pathname.startsWith("/api/")) {
event.respondWith(
fetch(event.request).catch(() => caches.match(event.request))
);
return;
}
event.respondWith(
caches.match(event.request).then((cached) => {
const network = fetch(event.request)
.then((response) => {
const clone = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
return response;
})
.catch(() => cached);
return cached || network;
})
);
});