add manifest.json and service worker

This commit is contained in:
2026-01-01 18:20:39 -06:00
parent c00e1e17fa
commit cfb06aea25
6 changed files with 100 additions and 0 deletions

View File

@@ -20,6 +20,8 @@
<link rel="stylesheet" href="~/css/inter.css" asp-append-version="true" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
<!--<link rel="stylesheet" href="~/foundation_system.styles.css" asp-append-version="true"/>-->
<link rel="manifest" href="~/manifest.json">
<meta name="theme-color" content="#1e293b">
@RenderSection("Styles", required: false)
</head>
<body>
@@ -78,5 +80,14 @@
<script src="~/js/sweetalert.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('Service Worker registrado', reg))
.catch(err => console.log('Error registrando Service Worker', err));
});
}
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 642 KiB

After

Width:  |  Height:  |  Size: 141 KiB

View File

@@ -0,0 +1,24 @@
{
"name": "Foundation System",
"short_name": "Foundation",
"description": "Sistema de gestión para fundaciones sin fines de lucro",
"start_url": "/",
"display": "standalone",
"background_color": "#f8fafc",
"theme_color": "#1e293b",
"orientation": "portrait",
"icons": [
{
"src": "/assets/icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "/assets/icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
]
}

View File

@@ -0,0 +1,65 @@
const CACHE_NAME = "foundation-cache-v1";
const ASSETS_TO_CACHE = [
"/",
"/css/site.css",
"/css/inter.css",
"/css/bootstrap-icons.min.css",
"/css/all.min.css",
"/lib/bootstrap/dist/css/bootstrap.min.css",
"/lib/jquery/dist/jquery.min.js",
"/lib/bootstrap/dist/js/bootstrap.bundle.min.js",
"/js/site.js",
];
// Install Event
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
return cache.addAll(ASSETS_TO_CACHE);
})
);
self.skipWaiting();
});
// Activate Event
self.addEventListener("activate", (event) => {
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cache) => {
if (cache !== CACHE_NAME) {
return caches.delete(cache);
}
})
);
})
);
self.clients.claim();
});
// Fetch Event - Stale-While-Revalidate Strategy
self.addEventListener("fetch", (event) => {
// Skip non-GET requests
if (event.request.method !== "GET") return;
event.respondWith(
caches.open(CACHE_NAME).then((cache) => {
return cache.match(event.request).then((cachedResponse) => {
const fetchedResponse = fetch(event.request)
.then((networkResponse) => {
// Update cache with new response
if (networkResponse.ok) {
cache.put(event.request, networkResponse.clone());
}
return networkResponse;
})
.catch(() => {
// If network fails and no cache, maybe return an offline page
return cachedResponse;
});
return cachedResponse || fetchedResponse;
});
})
);
});