diff --git a/index.html b/index.html index c787a15..d3b6948 100644 --- a/index.html +++ b/index.html @@ -18,6 +18,7 @@ De web a PWA. Copyright Babel. + (y ahora Pablo participa también) - \ No newline at end of file + diff --git a/pwabuilder-sw.js b/pwabuilder-sw.js new file mode 100644 index 0000000..09e240f --- /dev/null +++ b/pwabuilder-sw.js @@ -0,0 +1,47 @@ +// This is the "Offline page" service worker + +importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js'); + +const CACHE = "pwabuilder-page"; + +// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html"; +const offlineFallbackPage = "ToDo-replace-this-name.html"; + +self.addEventListener("message", (event) => { + if (event.data && event.data.type === "SKIP_WAITING") { + self.skipWaiting(); + } +}); + +self.addEventListener('install', async (event) => { + event.waitUntil( + caches.open(CACHE) + .then((cache) => cache.add(offlineFallbackPage)) + ); +}); + +if (workbox.navigationPreload.isSupported()) { + workbox.navigationPreload.enable(); +} + +self.addEventListener('fetch', (event) => { + if (event.request.mode === 'navigate') { + event.respondWith((async () => { + try { + const preloadResp = await event.preloadResponse; + + if (preloadResp) { + return preloadResp; + } + + const networkResp = await fetch(event.request); + return networkResp; + } catch (error) { + + const cache = await caches.open(CACHE); + const cachedResp = await cache.match(offlineFallbackPage); + return cachedResp; + } + })()); + } +}); \ No newline at end of file diff --git a/sw.js b/sw.js deleted file mode 100644 index 80e2171..0000000 --- a/sw.js +++ /dev/null @@ -1,2 +0,0 @@ -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