| 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 | "agrega.html", |
| 31 | "ayuda.html", |
| 32 | "favicon.ico", |
| 33 | "index.html", |
| 34 | "modifica.html", |
| 35 | "site.webmanifest", |
| 36 | "css/baseline.css", |
| 37 | "css/colors.css", |
| 38 | "css/elevation.css", |
| 39 | "css/estilos.css", |
| 40 | "css/material-symbols-outlined.css", |
| 41 | "css/md-fab-primary.css", |
| 42 | "css/md-filled-text-field.css", |
| 43 | "css/md-headline.css", |
| 44 | "css/md-list.css", |
| 45 | "css/md-standard-icon-button.css", |
| 46 | "css/md-tab.css", |
| 47 | "css/motion.css", |
| 48 | "css/palette.css", |
| 49 | "css/roboto.css", |
| 50 | "css/shape.css", |
| 51 | "css/state.css", |
| 52 | "css/transicion_pestanas.css", |
| 53 | "css/typography.css", |
| 54 | "css/theme/dark.css", |
| 55 | "css/theme/light.css", |
| 56 | "fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].codepoints", |
| 57 | "fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf", |
| 58 | "fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].woff2", |
| 59 | "fonts/roboto-v32-latin-regular.woff2", |
| 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/screenshot_horizontal.png", |
| 70 | "img/screenshot_vertical.png", |
| 71 | "js/nav-tab-fixed.js", |
| 72 | "js/lib/ES_APPLE.js", |
| 73 | "js/lib/getAttribute.js", |
| 74 | "js/lib/manejaErrores.js", |
| 75 | "js/lib/muestraError.js", |
| 76 | "js/lib/muestraTextoDeAyuda.js", |
| 77 | "js/lib/ProblemDetailsError.js", |
| 78 | "js/lib/querySelector.js", |
| 79 | "js/lib/registraServiceWorker.js", |
| 80 | "js/lib/resaltaSiEstasEn.js", |
| 81 | "js/lib/custom/md-app-bar.js", |
| 82 | "ungap/custom-elements.js", |
| 83 | "/" |
| 84 | ] |
| 85 | |
| 86 | |
| 87 | if (self instanceof ServiceWorkerGlobalScope) { |
| 88 | |
| 89 | self.addEventListener("install", |
| 90 | ( evt) => { |
| 91 | console.log("El service worker se está instalando.") |
| 92 | evt.waitUntil(llenaElCache()) |
| 93 | }) |
| 94 | |
| 95 | |
| 96 | self.addEventListener("fetch", ( evt) => { |
| 97 | if (evt.request.method === "GET") { |
| 98 | evt.respondWith(buscaLaRespuestaEnElCache(evt)) |
| 99 | } |
| 100 | }) |
| 101 | |
| 102 | |
| 103 | self.addEventListener("activate", |
| 104 | () => console.log("El service worker está activo.")) |
| 105 | } |
| 106 | |
| 107 | async function llenaElCache() { |
| 108 | console.log("Intentando cargar caché:", CACHE) |
| 109 | |
| 110 | const keys = await caches.keys() |
| 111 | for (const key of keys) { |
| 112 | await caches.delete(key) |
| 113 | } |
| 114 | |
| 115 | const cache = await caches.open(CACHE) |
| 116 | |
| 117 | await cache.addAll(ARCHIVOS) |
| 118 | console.log("Cache cargado:", CACHE) |
| 119 | console.log("Versión:", VERSION) |
| 120 | } |
| 121 | |
| 122 | |
| 123 | async function buscaLaRespuestaEnElCache(evt) { |
| 124 | |
| 125 | const cache = await caches.open(CACHE) |
| 126 | const request = evt.request |
| 127 | |
| 128 | |
| 129 | const response = await cache.match(request, { ignoreSearch: true }) |
| 130 | if (response === undefined) { |
| 131 | |
| 132 | |
| 133 | return fetch(request) |
| 134 | } else { |
| 135 | |
| 136 | return response |
| 137 | } |
| 138 | } |