-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.min.js
3 lines (2 loc) · 4.41 KB
/
service-worker.min.js
1
2
3
"use strict";function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}var CACHE_VERSION=1,BASE_CACHE_FILES=["/css/style.min.css","/js/theme.min.js","/site.webmanifest","/images/fixit.svg"],OFFLINE_CACHE_FILES=["/css/style.min.css","/js/theme.min.js","/site.webmanifest","/images/fixit.svg","/offline/"],NOT_FOUND_CACHE_FILES=["/css/style.min.css","/js/theme.min.js","/site.webmanifest","/images/fixit.svg","/404.html"],OFFLINE_PAGE="/offline/",NOT_FOUND_PAGE="/404.html",CACHE_VERSIONS={assets:"assets-v1",content:"content-v1",offline:"offline-v1",notFound:"404-v1"},MAX_TTL={"/":3600,html:3600,json:86400,js:86400,css:86400},CACHE_BLACKLIST=[function(a){return!a.startsWith("http://localhost")}],SUPPORTED_METHODS=["GET"];function isBlacklisted(a){return!!(0<CACHE_BLACKLIST.length)&&!CACHE_BLACKLIST.filter(function(b){return!("function"!=typeof b)&&!b(a)}).length}function getFileExtension(a){var b=a.split(".").reverse()[0].split("?")[0];return b.endsWith("/")?"/":b}function getTTL(a){if("string"==typeof a){var b=getFileExtension(a);return"number"==typeof MAX_TTL[b]?MAX_TTL[b]:null}return null}function installServiceWorker(){return Promise.all([caches.open(CACHE_VERSIONS.assets).then(function(a){return a.addAll(BASE_CACHE_FILES)}),caches.open(CACHE_VERSIONS.offline).then(function(a){return a.addAll(OFFLINE_CACHE_FILES)}),caches.open(CACHE_VERSIONS.notFound).then(function(a){return a.addAll(NOT_FOUND_CACHE_FILES)})]).then(function(){return self.skipWaiting()})}function cleanupLegacyCache(){var a=Object.keys(CACHE_VERSIONS).map(function(a){return CACHE_VERSIONS[a]});return new Promise(function(b,c){caches.keys().then(function(b){return b.filter(function(b){return!~a.indexOf(b)})}).then(function(a){a.length?Promise.all(a.map(function(a){return caches.delete(a)})).then(function(){b()}).catch(function(a){c(a)}):b()}).catch(function(a){c(a)})})}self.addEventListener("install",function(a){a.waitUntil(Promise.all([installServiceWorker(),self.skipWaiting()]))}),self.addEventListener("activate",function(a){a.waitUntil(Promise.all([cleanupLegacyCache(),self.clients.claim(),self.skipWaiting()]).catch(function(a){console.log(a),self.skipWaiting()}))}),self.addEventListener("fetch",function(a){a.respondWith(caches.open(CACHE_VERSIONS.content).then(function(b){return b.match(a.request).then(function(c){if(c){var d,e=c.headers.entries(),f=null,g=_createForOfIteratorHelper(e);try{for(g.s();!(d=g.n()).done;){var j=d.value;"date"===j[0]&&(f=new Date(j[1]))}}catch(a){g.e(a)}finally{g.f()}if(f){var h=parseInt((new Date().getTime()-f.getTime())/1e3),i=getTTL(a.request.url);return i&&h>i?new Promise(function(d){return fetch(a.request.clone()).then(function(e){e?(b.put(a.request,e.clone()),d(e)):d(c)}).catch(function(){d(c)})}).catch(function(a){return console.log(a),c}):c}return c}return null}).then(function(c){return c?c:fetch(a.request.clone()).then(function(c){return 400>c.status?(~SUPPORTED_METHODS.indexOf(a.request.method)&&!isBlacklisted(a.request.url)&&"http"===a.request.url.slice(0,4)&&b.put(a.request,c.clone()),c):caches.open(CACHE_VERSIONS.notFound).then(function(a){return a.match(NOT_FOUND_PAGE)})}).then(function(a){if(a)return a}).catch(function(){return caches.open(CACHE_VERSIONS.offline).then(function(a){return a.match(OFFLINE_PAGE)})})}).catch(function(a){throw console.error(" Error in fetch handler:",a),a})}))});
//# sourceMappingURL=service-worker.min.js.map