UNPKG

basb-cli

Version:
3 lines (2 loc) 1.75 kB
const e="MarkdownBlog-v0.2.0",t=["./dist/imgs/sun.svg","./dist/imgs/moon.svg","./dist/imgs/homepage.svg","./dist/imgs/broken-image.svg","./dist/imgs/favicon.png"],s=[/\/dist\/libs\//,"./dist/imgs/search.svg","./dist/imgs/rss.svg","./dist/imgs/fab-switch.svg","./dist/imgs/fab-catalog.svg","./dist/imgs/fab-back-to-top.svg","./dist/imgs/fab-back-to-parent.svg","./dist/imgs/fab-zoom-in.svg","./dist/imgs/fab-zoom-out.svg"];function n(){const e=location.href,t=e.indexOf("#");return-1!==t?e.substring(0,t):e}self.addEventListener("install",(s=>{console.log("[Service Worker] Installing..."),s.waitUntil((async()=>{const s=await caches.open(e);console.log("[Service Worker] Caching all: app shell and content");for(const e of t)try{await s.add(e)}catch(t){console.log("[Service Worker] Cache error when requesting resource "+e),console.error(t)}})())})),self.addEventListener("activate",(t=>{t.waitUntil((async()=>{const t=await caches.keys();await Promise.all(t.filter((t=>t!==e)).map((e=>caches.delete(e))))})()),console.log("[Service Worker] Activated")})),self.addEventListener("fetch",(t=>{const o=t.request.url;(function(e){const t=new URL(n()),s=new URL(e);return t.origin===s.origin})(o)&&t.respondWith(async function(t){const o=await caches.open(e),i=await o.match(t);if(i)return i;let r;try{r=await fetch(t,{mode:"no-cors"})}catch(e){return new Response("Network error happened: "+e,{status:408,headers:{"Content-Type":"text/plain"}})}return function(e){const t=s,o=n();for(const s of t)if("string"==typeof s){if(new URL(s,o).href===e)return!0}else if(s instanceof RegExp){if(s.test(e))return!0}else console.error("Unexpected presetted optional resource path: "+s);return!1}(t)&&o.put(t,r.clone()),r}(o))})); //# sourceMappingURL=./dist/sw.js.map