1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | const VERSION = "1.00" |
19 | |
20 | |
21 | |
22 | |
23 | const CACHE = "pwamd" |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | const ARCHIVOS = [ |
30 | "ayuda.html", |
31 | "botones.html", |
32 | "campos.html", |
33 | "favicon.ico", |
34 | "formulario.html", |
35 | "iconos.html", |
36 | "index.html", |
37 | "interruptor.html", |
38 | "navbar.html", |
39 | "navtab.html", |
40 | "navTabFixed.html", |
41 | "one-line.html", |
42 | "secundaria.html", |
43 | "segmentado.html", |
44 | "select.html", |
45 | "site.webmanifest", |
46 | "slider.html", |
47 | "tarjetas.html", |
48 | "three-line.html", |
49 | "two-line.html", |
50 | "css/dark-hc.css", |
51 | "css/dark-mc.css", |
52 | "css/dark.css", |
53 | "css/estilos.css", |
54 | "css/light-hc.css", |
55 | "css/light-mc.css", |
56 | "css/light.css", |
57 | "css/transicion_completa.css", |
58 | "css/transicion_pestanas.css", |
59 | "img/Escultura_de_coyote.jpeg", |
60 | "img/icono2048.png", |
61 | "img/maskable_icon.png", |
62 | "img/maskable_icon_x128.png", |
63 | "img/maskable_icon_x192.png", |
64 | "img/maskable_icon_x384.png", |
65 | "img/maskable_icon_x48.png", |
66 | "img/maskable_icon_x512.png", |
67 | "img/maskable_icon_x72.png", |
68 | "img/maskable_icon_x96.png", |
69 | "img/pexels-craig-dennis-3701822.jpg", |
70 | "img/pexels-creative-workshop-3978352.jpg", |
71 | "img/pexels-erik-karits-3732453.jpg", |
72 | "img/pexels-esteban-arango-10226903.jpg", |
73 | "img/pexels-moises-patrício-10961948.jpg", |
74 | "img/pexels-ralph-2270848.jpg", |
75 | "img/pexels-rasmus-svinding-35435.jpg", |
76 | "img/pexels-steve-397857.jpg", |
77 | "img/pexels-vadim-b-141496.jpg", |
78 | "img/screenshot_horizontal.png", |
79 | "img/screenshot_vertical.png", |
80 | "js/configura.js", |
81 | "js/nav-bar.js", |
82 | "js/nav-drw.js", |
83 | "js/nav-tab-fixed.js", |
84 | "js/nav-tab-scrollable.js", |
85 | "js/registraServiceWorker.js", |
86 | "lib/css/material-symbols-outlined.css", |
87 | "lib/css/md-cards.css", |
88 | "lib/css/md-fab-primary.css", |
89 | "lib/css/md-filled-button.css", |
90 | "lib/css/md-filled-text-field.css", |
91 | "lib/css/md-list.css", |
92 | "lib/css/md-menu.css", |
93 | "lib/css/md-navigation-bar.css", |
94 | "lib/css/md-outline-button.css", |
95 | "lib/css/md-ripple.css", |
96 | "lib/css/md-segmented-button.css", |
97 | "lib/css/md-slider-field.css", |
98 | "lib/css/md-standard-icon-button.css", |
99 | "lib/css/md-switch.css", |
100 | "lib/css/md-tab.css", |
101 | "lib/css/md-top-app-bar.css", |
102 | "lib/css/roboto.css", |
103 | "lib/fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].codepoints", |
104 | "lib/fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf", |
105 | "lib/fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].woff2", |
106 | "lib/fonts/roboto-v32-latin-regular.woff2", |
107 | "lib/js/abreElementoHtml.js", |
108 | "lib/js/cierraElementoHtmo.js", |
109 | "lib/js/exportaAHtml.js", |
110 | "lib/js/getAttribute.js", |
111 | "lib/js/htmlentities.js", |
112 | "lib/js/muestraError.js", |
113 | "lib/js/muestraTextoDeAyuda.js", |
114 | "lib/js/ProblemDetails.js", |
115 | "lib/js/querySelector.js", |
116 | "lib/js/resaltaSiEstasEn.js", |
117 | "lib/js/const/ES_APPLE.js", |
118 | "lib/js/custom/md-menu-button.js", |
119 | "lib/js/custom/md-options-menu.js", |
120 | "lib/js/custom/md-overflow-button.js", |
121 | "lib/js/custom/md-overflow-menu.js", |
122 | "lib/js/custom/md-select-menu.js", |
123 | "lib/js/custom/md-slider-field.js", |
124 | "lib/js/custom/md-top-app-bar.js", |
125 | "lib/js/custom/MdNavigationDrawer.js", |
126 | "material-tokens/css/baseline.css", |
127 | "material-tokens/css/colors.css", |
128 | "material-tokens/css/elevation.css", |
129 | "material-tokens/css/motion.css", |
130 | "material-tokens/css/palette.css", |
131 | "material-tokens/css/shape.css", |
132 | "material-tokens/css/state.css", |
133 | "material-tokens/css/typography.css", |
134 | "material-tokens/css/theme/dark.css", |
135 | "material-tokens/css/theme/light.css", |
136 | "ungap/custom-elements.js", |
137 | "/" |
138 | ] |
139 | |
140 | |
141 | if (self instanceof ServiceWorkerGlobalScope) { |
142 | |
143 | self.addEventListener("install", |
144 | ( evt) => { |
145 | console.log("El service worker se está instalando.") |
146 | evt.waitUntil(llenaElCache()) |
147 | }) |
148 | |
149 | |
150 | self.addEventListener("fetch", ( evt) => { |
151 | if (evt.request.method === "GET") { |
152 | evt.respondWith(buscaLaRespuestaEnElCache(evt)) |
153 | } |
154 | }) |
155 | |
156 | |
157 | self.addEventListener("activate", |
158 | () => console.log("El service worker está activo.")) |
159 | } |
160 | |
161 | async function llenaElCache() { |
162 | console.log("Intentando cargar caché:", CACHE) |
163 | |
164 | const keys = await caches.keys() |
165 | for (const key of keys) { |
166 | await caches.delete(key) |
167 | } |
168 | |
169 | const cache = await caches.open(CACHE) |
170 | |
171 | await cache.addAll(ARCHIVOS) |
172 | console.log("Cache cargado:", CACHE) |
173 | console.log("Versión:", VERSION) |
174 | } |
175 | |
176 | |
177 | async function buscaLaRespuestaEnElCache(evt) { |
178 | |
179 | const cache = await caches.open(CACHE) |
180 | const request = evt.request |
181 | |
182 | |
183 | const response = await cache.match(request, { ignoreSearch: true }) |
184 | if (response === undefined) { |
185 | |
186 | |
187 | return fetch(request) |
188 | } else { |
189 | |
190 | return response |
191 | } |
192 | } |