File size: 1,021 Bytes
6cfe16d
 
 
 
 
f7f0a1a
 
 
 
 
 
 
 
 
6cfe16d
f7f0a1a
 
6cfe16d
 
 
 
f7f0a1a
 
 
6cfe16d
f7f0a1a
 
 
6cfe16d
f7f0a1a
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* 
   SERVICE WORKER - Maker Space
   Permite el funcionamiento offline y la caché de archivos estáticos (PWA)
*/

const CACHE_NAME = 'maker-station-v1';
const ASSETS = [
    '/',
    '/static/css/style.css',
    '/static/js/script.js',
    '/static/assets/favicon.png',
    '/static/assets/icon192x192.png'
];

// Evento de Instalación: Se ejecuta cuando se registra el SW por primera vez
self.addEventListener('install', (event) => {
    event.waitUntil(
        caches.open(CACHE_NAME).then((cache) => {
            console.log('DEBUG: Precargando archivos en caché');
            return cache.addAll(ASSETS);
        })
    );
});

// Evento de Intercepción de Peticiones: Permite servir archivos desde la caché si la red falla
self.addEventListener('fetch', (event) => {
    event.respondWith(
        caches.match(event.request).then((response) => {
            // Retorna la respuesta de la caché o realiza la petición a internet
            return response || fetch(event.request);
        })
    );
});