-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServiceWorker.js
31 lines (29 loc) · 1.1 KB
/
ServiceWorker.js
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
// Definir el nombre de la caché y los recursos para almacenar en caché
const CACHE_NAME = 'my-cache-v1';
const urlsToCache = [
// Agrega aquí otros recursos que quieras guardar en caché
'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js',
'https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.js',
'https://fonts.googleapis.com/css2?family=Aboreto&display=swap',
'https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap',
'https://polyfill.io/v3/polyfill.min.js?features=es6'
];
// Instalación del Service Worker y almacenamiento en caché de recursos
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
return cache.addAll(urlsToCache);
})
);
});
// Manejo de solicitudes de red
self.addEventListener('fetch', event => {
event.respondWith(
// Intenta primero obtener el recurso de la red
fetch(event.request).catch(() => {
// Si la solicitud a la red falla, intenta obtener el recurso desde el caché
return caches.match(event.request);
})
);
});