diff --git a/index.html b/index.html index d3b6948..80aa96d 100644 --- a/index.html +++ b/index.html @@ -2,23 +2,25 @@ - - - + + + Babel PWA - + - De web a PWA. + De web a PWA. - Copyright Babel. - (y ahora Pablo participa también) +

Descargar ZIP de prueba

+ Descargar archivo ZIP + + Copyright Babel. (y ahora Pablo participa también) diff --git a/sw.js b/sw.js index 80e2171..4b3c5e2 100644 --- a/sw.js +++ b/sw.js @@ -1,2 +1,37 @@ -if(!self.define){let e,i={};const n=(n,r)=>(n=new URL(n+".js",r).href,i[n]||new Promise((i=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=i,document.head.appendChild(e)}else e=n,importScripts(n),i()})).then((()=>{let e=i[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e})));self.define=(r,o)=>{const s=e||("document"in self?document.currentScript.src:"")||location.href;if(i[s])return;let t={};const c=e=>n(e,s),f={module:{uri:s},exports:t,require:c};i[s]=Promise.all(r.map((e=>f[e]||c(e)))).then((e=>(o(...e),t)))}}define(["./workbox-5fc434c9"],(function(e){"use strict";self.addEventListener("message",(e=>{e.data&&"SKIP_WAITING"===e.data.type&&self.skipWaiting()})),e.precacheAndRoute([{url:"images/icono.png",revision:"e134b60d9dc4271a672b6cc947f22bf5"},{url:"images/principal-horizontal.png",revision:"688431d1fd27dead61081ffe700e9593"},{url:"index.html",revision:"40624c4cf34373f498b61ad6be2ec205"},{url:"manifest.json",revision:"22bd873e24ef003621065a36cfe336f8"}],{ignoreURLParametersMatching:[/^utm_/,/^fbclid$/]})})); -//# sourceMappingURL=sw.js.map +const CACHE_NAME = 'cool-cache'; + +// Add whichever assets you want to precache here: +const PRECACHE_ASSETS = [ + '/assets/', + '/src/' +] + +// Listener for the install event - precaches our assets list on service worker install. +self.addEventListener('install', event => { + event.waitUntil((async () => { + const cache = await caches.open(CACHE_NAME); + cache.addAll(PRECACHE_ASSETS); + })()); +}); + +self.addEventListener('activate', event => { + event.waitUntil(self.clients.claim()); +}); + +self.addEventListener('fetch', event => { + event.respondWith(async () => { + const cache = await caches.open(CACHE_NAME); + + // match the request to our cache + const cachedResponse = await cache.match(event.request); + + // check if we got a valid response + if (cachedResponse !== undefined) { + // Cache hit, return the resource + return cachedResponse; + } else { + // Otherwise, go to the network + return fetch(event.request) + }; + }); +}); \ No newline at end of file