Repository navigation
Expand file tree
/
Copy pathsw.js
More file actions
1 lines (1 loc) · 4.88 KB
/
Copy pathsw.js
File metadata and controls
1 lines (1 loc) · 4.88 KB
1
var CACHE_VERSION="2019-02-08T17:07:30.321Z",CURRENT_CACHES={prefetch:"prefetch-cache-v"+CACHE_VERSION},INCLUDED=["searchcode.com","fanyi.youdao.com","api.github.com"],CACHE_ONLY=["fanyi.youdao.com","api.github.com"],NETWORK_ONLY=[],EXCLUDED=[];function matchLocation(e,t){return t.find(function(t){return-1!==e.indexOf(t)})}self.addEventListener("install",function(e){self.skipWaiting();var t=Date.now(),s=["./","opensearch.xml","css/app.7161ff35.css","css/app.css","css/lib.365f8ae0.css","css/lib.css","fonts/Dressedless_Three.svg","fonts/Dressedless_Three.ttf","fonts/FontAwesome.otf","fonts/LatoLatin-Bold.woff2","fonts/LatoLatin-BoldItalic.woff2","fonts/LatoLatin-Italic.woff2","fonts/LatoLatin-Regular.woff2","fonts/fontawesome-webfont.eot","fonts/fontawesome-webfont.svg","fonts/fontawesome-webfont.ttf","fonts/fontawesome-webfont.woff","fonts/fontawesome-webfont.woff2","images/404_dribbble.ae94d03c.gif","images/404_dribbble.gif","images/codelf_logo.f4ae25bd.png","images/codelf_logo.png","images/paypal.69412e83.png","images/paypal.png","images/twohardtings.0db8462a.jpg","images/twohardtings.jpg","images/wechatpay.48ba089d.jpg","images/wechatpay.jpg","images/zhifubao.70c19370.png","images/zhifubao.png","js/app.a7ec4baf.js","js/app.js","js/lib.052e059d.js","js/lib.js","css/themes/default/assets/images/flags.png","css/themes/default/assets/fonts/brand-icons.eot","css/themes/default/assets/fonts/brand-icons.svg","css/themes/default/assets/fonts/brand-icons.ttf","css/themes/default/assets/fonts/brand-icons.woff","css/themes/default/assets/fonts/brand-icons.woff2","css/themes/default/assets/fonts/icons.eot","css/themes/default/assets/fonts/icons.otf","css/themes/default/assets/fonts/icons.svg","css/themes/default/assets/fonts/icons.ttf","css/themes/default/assets/fonts/icons.woff","css/themes/default/assets/fonts/icons.woff2","css/themes/default/assets/fonts/outline-icons.eot","css/themes/default/assets/fonts/outline-icons.svg","css/themes/default/assets/fonts/outline-icons.ttf","css/themes/default/assets/fonts/outline-icons.woff","css/themes/default/assets/fonts/outline-icons.woff2"];console.log("Handling install event. Resources to prefetch:",s),e.waitUntil(caches.open(CURRENT_CACHES.prefetch).then(function(e){var n=s.map(function(s){var n=new URL(s,location.href);n.search+=(n.search?"&":"?")+"cache-bust="+t;var o=new Request(n,{mode:"no-cors"});return fetch(o).then(function(t){if(t.status>=400)throw new Error("request for "+s+" failed with status "+t.statusText);return e.put(s,t)}).catch(function(e){console.error("Not caching "+s+" due to "+e)})});return Promise.all(n).then(function(){console.log("Pre-fetching complete.")})}).catch(function(e){console.error("Pre-fetching failed:",e)}))}),self.addEventListener("activate",function(e){var t=Object.keys(CURRENT_CACHES).map(function(e){return CURRENT_CACHES[e]});e.waitUntil(caches.keys().then(function(e){return Promise.all(e.map(function(e){if(-1===t.indexOf(e))return console.log("Deleting out of date cache:",e),caches.delete(e)}))}))}),self.addEventListener("fetch",function(e){console.log("Handling fetch event for",e.request.url);var t=new URL(e.request.url);"navigate"===e.request.mode?(console.log("request mode:",e.request.mode),e.respondWith(async function(){const s=t;s.search="";const n=fetch(s),o=n.then(e=>e.clone());return e.waitUntil(async function(){const e=await caches.open(CURRENT_CACHES.prefetch);await e.put(s,await o)}()),await caches.match(s)||n}())):matchLocation(t.href,INCLUDED)&&!matchLocation(t.href,EXCLUDED)&&/get/i.test(e.request.method)?matchLocation(t.href,NETWORK_ONLY)?(console.log("network-falling-back-to-caches:",e.request.url),e.respondWith(caches.open(CURRENT_CACHES.prefetch).then(function(t){return fetch(e.request).then(function(s){return t.put(e.request,s.clone()),s}).catch(function(){return t.match(e.request).then(function(e){return e})})}))):matchLocation(t.href,CACHE_ONLY)?(console.log("cache-falling-back-to-network:",e.request.url),e.respondWith(caches.open(CURRENT_CACHES.prefetch).then(function(t){return t.match(e.request).then(function(s){return s||fetch(e.request).then(function(s){return t.put(e.request,s.clone()),s})})}))):(console.log("cache-then-network:",e.request.url),e.respondWith(caches.open(CURRENT_CACHES.prefetch).then(function(t){return t.match(e.request).then(function(s){var n=fetch(e.request).then(function(s){return t.put(e.request,s.clone()),s});return s||n})}))):t.origin==location.origin&&(console.log("request origin:",t.origin),e.respondWith(caches.match(e.request).then(function(t){return t?(console.log("Found response in cache:",t),t):(console.log("No response found in cache. About to fetch from network..."),fetch(e.request).then(function(e){return console.log("Response from network is:",e),e}).catch(function(e){throw console.error("Fetching failed:",e),e}))})))}),"storage"in navigator&&"estimate"in navigator.storage&&navigator.storage.estimate().then(e=>{console.log(`Using ${e.usage} out of ${e.quota} bytes.`)});