-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupup.sw.min.js
8 lines (8 loc) · 2.05 KB
/
upup.sw.min.js
1
2
3
4
5
6
7
8
Cache.prototype.add||(Cache.prototype.add=function(a){return this.addAll([a])}),Cache.prototype.addAll||(Cache.prototype.addAll=function(a){function b(a){this.name="NetworkError",this.code=19,this.message=a}var c=this;return b.prototype=Object.create(Error.prototype),Promise.resolve().then(function(){if(arguments.length<1)throw new TypeError;return a=a.map(function(a){return a instanceof Request?a:String(a)}),Promise.all(a.map(function(a){"string"==typeof a&&(a=new Request(a));var c=new URL(a.url).protocol;if("http:"!==c&&"https:"!==c)throw new b("Invalid scheme");return fetch(a.clone())}))}).then(function(b){return Promise.all(b.map(function(b,d){return c.put(a[d],b)}))}).then(function(){return void 0})}),CacheStorage.prototype.match||(CacheStorage.prototype.match=function(a,b){var c=this;return this.keys().then(function(d){var e;return d.reduce(function(d,f){return d.then(function(){return e||c.open(f).then(function(c){return c.match(a,b)}).then(function(a){return e=a})})},Promise.resolve())})});
//! UpUp ServiceWorker
//! version : 0.1.1
//! author : Tal Ater @TalAter
//! license : MIT
//! https://github.com/TalAter/UpUp
var _CACHE_NAME="upup-cache";self.addEventListener("message",function(a){"set-settings"===a.data.action&&_setSettings(a.data.settings)}),self.addEventListener("fetch",function(a){a.respondWith(fetch(a.request.url,{mode:"no-cors"})["catch"](function(){return caches.match(a.request).then(function(b){return b?b:a.request.headers.get("accept").includes("text/html")?caches.match("sw-offline-content"):void 0})}))});var _setSettings=function(a){return caches.open(_CACHE_NAME).then(function(b){return a.assets&&b.addAll(a.assets.map(function(a){return new Request(a,{mode:"no-cors"})})),a["content-url"]?fetch(a["content-url"],{mode:"no-cors"}).then(function(a){return b.put("sw-offline-content",a)}):a.content?b.put("sw-offline-content",_buildResponse(a.content)):b.put("sw-offline-content",_buildResponse("You are offline"))})},_buildResponse=function(a){return new Response(a,{headers:{"Content-Type":"text/html"}})};
//# sourceMappingURL=upup.sw.min.js.map