Skip to content

Commit

Permalink
add sw
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo committed Oct 4, 2024
1 parent b5386a2 commit fd388c1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
24 changes: 13 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
<html lang="es">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width_device-width, inital-scale=1.0">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Babel PWA</title>
<link rel="manifest" href="./manifest.json">
<script type="text/javascript">
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("sw.js");
}
</script>
<script type="text/javascript">
if (typeof navigator.serviceWorker !== 'undefined') {
navigator.serviceWorker.register('sw.js');
}
</script>
</head>

<body>
De web a PWA.
De web a PWA.

Copyright Babel.
(y ahora Pablo participa también)
<h2>Descargar ZIP de prueba</h2>
<a href="https://example.com/path/to/test_files.zip" download="test_files.zip">Descargar archivo ZIP</a>

Copyright Babel. (y ahora Pablo participa también)
</body>

</html>
39 changes: 37 additions & 2 deletions sw.js
Original file line number Diff line number Diff line change
@@ -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)
};
});
});

0 comments on commit fd388c1

Please sign in to comment.