| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | const VERSION = "1.0" |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | const CACHE = "pwamd" |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | const ARCHIVOS = [ |
| 30 | "ayuda.html", |
| 31 | "css/estilos.css", |
| 32 | "css/material-symbols-outlined.css", |
| 33 | "css/transicion_pestanas.css", |
| 34 | "favicon.ico", |
| 35 | "fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].codepoints", |
| 36 | "fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf", |
| 37 | "fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].woff2", |
| 38 | "fonts/Roboto-Italic-VariableFont_wdth,wght.ttf", |
| 39 | "fonts/Roboto-VariableFont_wdth,wght.ttf", |
| 40 | "img/icono2048.png", |
| 41 | "img/maskable_icon.png", |
| 42 | "img/maskable_icon_x128.png", |
| 43 | "img/maskable_icon_x192.png", |
| 44 | "img/maskable_icon_x384.png", |
| 45 | "img/maskable_icon_x48.png", |
| 46 | "img/maskable_icon_x512.png", |
| 47 | "img/maskable_icon_x72.png", |
| 48 | "img/maskable_icon_x96.png", |
| 49 | "img/screenshot_horizontal.png", |
| 50 | "img/screenshot_vertical.png", |
| 51 | "index.html", |
| 52 | "js/nav-tab-fixed.js", |
| 53 | "js/registraServiceWorker.js", |
| 54 | "libclienteweb/abreElementoHtml.js", |
| 55 | "libclienteweb/cierraElementoHtmo.js", |
| 56 | "libclienteweb/ES_APPLE.js", |
| 57 | "libclienteweb/getAttribute.js", |
| 58 | "libclienteweb/manejaErrores.js", |
| 59 | "libclienteweb/muestraError.js", |
| 60 | "libclienteweb/muestraTextoDeAyuda.js", |
| 61 | "libclienteweb/ProblemDetailsError.js", |
| 62 | "libclienteweb/querySelector.js", |
| 63 | "libclienteweb/resaltaSiEstasEn.js", |
| 64 | "libmde/md-app-bar.js", |
| 65 | "libmde/md-filled-button.css", |
| 66 | "libmde/md-filled-text-field.css", |
| 67 | "libmde/md-list.css", |
| 68 | "libmde/md-menu.css", |
| 69 | "libmde/md-options-menu.js", |
| 70 | "libmde/md-outline-button.css", |
| 71 | "libmde/md-select-menu.js", |
| 72 | "libmde/md-tab.css", |
| 73 | "material-tokens/css/baseline.css", |
| 74 | "material-tokens/css/colors.css", |
| 75 | "material-tokens/css/elevation.css", |
| 76 | "material-tokens/css/motion.css", |
| 77 | "material-tokens/css/palette.css", |
| 78 | "material-tokens/css/shape.css", |
| 79 | "material-tokens/css/state.css", |
| 80 | "material-tokens/css/theme/dark.css", |
| 81 | "material-tokens/css/theme/light.css", |
| 82 | "material-tokens/css/typography.css", |
| 83 | "select.html", |
| 84 | "site.webmanifest", |
| 85 | "ungap/es.js", |
| 86 | "/" |
| 87 | ] |
| 88 | |
| 89 | |
| 90 | if (self instanceof ServiceWorkerGlobalScope) { |
| 91 | |
| 92 | self.addEventListener("install", |
| 93 | ( evt) => { |
| 94 | console.log("El service worker se está instalando.") |
| 95 | evt.waitUntil(llenaElCache()) |
| 96 | }) |
| 97 | |
| 98 | |
| 99 | self.addEventListener("fetch", ( evt) => { |
| 100 | if (evt.request.method === "GET") { |
| 101 | evt.respondWith(buscaLaRespuestaEnElCache(evt)) |
| 102 | } |
| 103 | }) |
| 104 | |
| 105 | |
| 106 | self.addEventListener("activate", |
| 107 | () => console.log("El service worker está activo.")) |
| 108 | } |
| 109 | |
| 110 | async function llenaElCache() { |
| 111 | console.log("Intentando cargar caché:", CACHE) |
| 112 | |
| 113 | const keys = await caches.keys() |
| 114 | for (const key of keys) { |
| 115 | await caches.delete(key) |
| 116 | } |
| 117 | |
| 118 | const cache = await caches.open(CACHE) |
| 119 | |
| 120 | await cache.addAll(ARCHIVOS) |
| 121 | console.log("Cache cargado:", CACHE) |
| 122 | console.log("Versión:", VERSION) |
| 123 | } |
| 124 | |
| 125 | |
| 126 | async function buscaLaRespuestaEnElCache(evt) { |
| 127 | |
| 128 | const cache = await caches.open(CACHE) |
| 129 | const request = evt.request |
| 130 | |
| 131 | |
| 132 | const response = await cache.match(request, { ignoreSearch: true }) |
| 133 | if (response === undefined) { |
| 134 | |
| 135 | |
| 136 | return fetch(request) |
| 137 | } else { |
| 138 | |
| 139 | return response |
| 140 | } |
| 141 | } |