feat(pwa): añade assets PWA que faltaban (manifest, sw.js, iconos)
El commit anterior (a3fd928) referenciaba /manifest.webmanifest,
/sw.js, /favicon-32.png y /apple-touch-icon.png en index.html y
main.jsx, pero los archivos no existían: el fallback SPA los servía
como index.html (200 text/html), así que la PWA no era instalable y
parecía que el desplegue no había actualizado.
Se añaden en public/ (Vite los copia a dist/ raíz):
- manifest.webmanifest: nombre, theme_color #8B0000, iconos any/maskable.
- sw.js: cache del shell con stale-while-revalidate (sirve cache al
instante y revalida en segundo plano) + network-first para /api/.
Versión de caché localesp-shell-v1.
- Iconos: favicon-32, apple-touch-icon (180), icon-192, icon-512 y
icon-512-maskable.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 204 KiB |
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "LocalESP · Locales Españoles",
|
||||
"short_name": "LocalESP",
|
||||
"description": "Directorio colaborativo de negocios locales por toda España",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#ffffff",
|
||||
"theme_color": "#8B0000",
|
||||
"lang": "es",
|
||||
"icons": [
|
||||
{ "src": "/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
|
||||
{ "src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" },
|
||||
{ "src": "/icon-512-maskable.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
const CACHE_NAME = "localesp-shell-v1";
|
||||
const SHELL_ASSETS = ["/", "/manifest.webmanifest", "/icon-192.png", "/icon-512.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;
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user