加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sw.js 31.94 KB
一键复制 编辑 原始数据 按行查看 历史
lisong 提交于 2021-07-20 16:01 . Site updated: 2021-07-20 16:01:38
/**
* 自动引入模板,在原有 sw-precache 插件默认模板基础上做的二次开发
*
* 因为是自定导入的模板,项目一旦生成,不支持随 sw-precache 的版本自动升级。
* 可以到 Lavas 官网下载 basic 模板内获取最新模板进行替换
*
*/
/* eslint-disable */
'use strict';
var precacheConfig = [["/bufferfly/about/index.html","bc00e01c6fe214d87ae4374b3a9b5a40"],["/bufferfly/archives/2020/07/index.html","9b58a78e5361414f309d07e9766f74b7"],["/bufferfly/archives/2020/08/index.html","2a6d86348883ee1337a4d8f2ceba97cd"],["/bufferfly/archives/2020/09/index.html","ab2f18fbdd1bc3aa216478e9d695102b"],["/bufferfly/archives/2020/index.html","c41c6210967c42f2d144461402d3168b"],["/bufferfly/archives/2021/07/index.html","9d8fdf068cd156fbddfd7ece31e03976"],["/bufferfly/archives/2021/index.html","5a5a850eca9fb3f5eb5fd46b5d337538"],["/bufferfly/archives/index.html","bf8a9b7c26acb3ce2a2bea8578ce542e"],["/bufferfly/bbs/index.html","5c331d515730cab34753d0905230eb77"],["/bufferfly/bufferfly/blog/1243066710.html","cb62209abafc2bcf81596185585b126b"],["/bufferfly/bufferfly/blog/3ba53770.html","0516d085c21ab4a8634583690523c351"],["/bufferfly/bufferfly/blog/4ad3c53.html","0773184201268cfd7eab0fe47d5d014d"],["/bufferfly/bufferfly/blog/50a2b841.html","9c041c29deb71995e7fe72d967c08000"],["/bufferfly/bufferfly/blog/871f3241.html","f2772857142fb35d9c848b3daa43342f"],["/bufferfly/bufferfly/blog/a1da6445.html","dc9b418493f0d41e44229e8d277aac63"],["/bufferfly/bufferfly/blog/f3908263.html","5d4b1df0f4eb95636813d6a0c5b0d3d7"],["/bufferfly/bufferfly/blog/f62be7ba.html","1f608962a669a84a73b765835b9e21ae"],["/bufferfly/categories/Hexo/index.html","a94ee1245a2bfb710c13d5fbee3c1d3a"],["/bufferfly/categories/Java那点事/Maven/index.html","b7088e5c8782edeb1b75d3f7d60e7ff0"],["/bufferfly/categories/Java那点事/index.html","52eeed9bdb16adaeed43d067e590f1f4"],["/bufferfly/categories/Java那点事/练手项目/index.html","4768f7c23029ec989fae55c5a5b56342"],["/bufferfly/categories/index.html","0f553f0003b9778c8783d9b17fcb311c"],["/bufferfly/categories/博客园博文/index.html","e8670e8631ac5779548fadd0b93e11d4"],["/bufferfly/categories/博客园博文/mybatis/index.html","311c197235d351363445084cd0190b16"],["/bufferfly/categories/博客园博文/博客美化/index.html","397a59e88156ac747653a7e7a5735243"],["/bufferfly/css/botui-theme-default.css","b3cd9f0f253c229ab91690d9dfa3deea"],["/bufferfly/css/botui.min.css","82e143779bd9e0957ef67d9172c8b18d"],["/bufferfly/css/cur.css","fa55e5d9bc7083748b0872cfd878d799"],["/bufferfly/css/custom.css","719762bc79cfeed4aaa138a06d06aaab"],["/bufferfly/css/customTag.css","f87bff7702ca5a96d8c5503d1eec2a4e"],["/bufferfly/css/font-OzCaramel.css","d1370fc94a746c3bd89a51366334f696"],["/bufferfly/css/fontAnimation.css","e438cbdce5ff14ae374d19c1e13d491b"],["/bufferfly/css/iconfont.css","a0a72c4490f747df6aacc7f10393241d"],["/bufferfly/css/index.css","bce524f207becae7a707e278b7863976"],["/bufferfly/css/var.css","d41d8cd98f00b204e9800998ecf8427e"],["/bufferfly/css/weather-plugin.css","b8ba7e50031bf42daf67b5946a505b05"],["/bufferfly/fonts/OzCaramel_Tiny.woff2","e1965e0fdbb2c70b1f8ad899081ca324"],["/bufferfly/img/404.jpg","4ef3cfb882b6dd4128da4c8745e9a507"],["/bufferfly/img/algolia.svg","88450dd56ea1a00ba772424b30b7d34d"],["/bufferfly/img/alipay.jpg","369a0a03e8bde22a168d6d7876c2d7ff"],["/bufferfly/img/avatar.png","38b843ce8d375dd746f3a7e53d288fc9"],["/bufferfly/img/banner/4.jpg","bbb7c6e21eb3e2349bb74de245cd5165"],["/bufferfly/img/comment_bg.gif","f313be601f776ff58e22d89c29f49c79"],["/bufferfly/img/comment_bg.webp","c9e6254ff7429e52b5b7f56d8acfb44a"],["/bufferfly/img/favicon.png","7a8c47cb5a2149c1a1af21e90ecd9ca7"],["/bufferfly/img/friend_404.gif","68af0be9d22722e74665ef44dd532ba8"],["/bufferfly/img/icp.png","6e26aed5ced63bc60524cc736611d39e"],["/bufferfly/img/loading.gif","d1cf8d9ccb6a2b3514a7d14332035a3c"],["/bufferfly/img/loading1.gif","3f21b4ceff2c6de89dd8d80d4178c1d1"],["/bufferfly/img/talk.gif","f87089028282607c90e25e7de91266e0"],["/bufferfly/img/valine_bg.png","27c5fdfc445c8c3d00d46206d3852fa6"],["/bufferfly/img/wechat.png","409e133fd42db1b8fd39fbab8956381e"],["/bufferfly/index.html","86d72ba8a6f3b6f395c45a21dfd11790"],["/bufferfly/js/main.js","f468f3bc967338f2dd7a6e06c2eef692"],["/bufferfly/js/search/algolia.js","533d980c0d50a0d0d7fe34c41a3e2100"],["/bufferfly/js/search/local-search.js","acb62dcdf7e90930da3f6bf07349fc21"],["/bufferfly/js/third-party/botui.js","8b886514e19ac87e635dcada4f5fec2e"],["/bufferfly/js/third-party/calendar.js","acaac30bf1b462053413c1f9e9a9fd48"],["/bufferfly/js/third-party/custom.js","176cc4b7e4b28ae27e5faa4d28159966"],["/bufferfly/js/third-party/customTags.js","45b78cba58e7e4985a424bf4236db4db"],["/bufferfly/js/third-party/flyfish.js","295e17b52f5c795ad5dd579d811cdb4b"],["/bufferfly/js/third-party/languages.js","1cad45b801777e910a5ca1120238a377"],["/bufferfly/js/third-party/piao.js","5c8c9ff4bb9bed49e333387a54eae9be"],["/bufferfly/js/third-party/snow.js","9229efbff74f8f45db54913b9b7f852b"],["/bufferfly/js/third-party/star.js","a324baf869e1bda007280e121d62fd18"],["/bufferfly/js/third-party/weather-config.js","989a06e4e393a664606564224afc45fe"],["/bufferfly/js/third-party/weather-plugin.js","e8fa2b39bc2fa4db22088f41cbf2d6a4"],["/bufferfly/js/tw_cn.js","b3810513e04b13b2d18c6b779c883f85"],["/bufferfly/js/utils.js","4cfc631de0e5f6ff12b2833cac848f27"],["/bufferfly/link/index.html","3c6dbfb643d65cbb19f0a9b8f375c6f1"],["/bufferfly/music/index.html","54c85af05173b21a0a8b3b9426db24e7"],["/bufferfly/photo/index.html","d2f0627730f7a02a12e15dece440c5b5"],["/bufferfly/shuoshuo/index.html","f3038bf0f12d90a3622b8953da752416"],["/bufferfly/sw-register.js","7d7618429d993e1bbb24ab98c356cbb0"],["/bufferfly/tags/Hexo/index.html","9d79198baada45632b4b69193afc792e"],["/bufferfly/tags/Java/index.html","fa29235a827e23e6efb8c884b6dcdfc7"],["/bufferfly/tags/Java那点事/index.html","4b353f756397a7d7c818384b37348399"],["/bufferfly/tags/Maven/index.html","bbaecaa6b8063522df54c23fa79a66fc"],["/bufferfly/tags/MyBatis/index.html","ea91ccc819f94f40490b18d199017f17"],["/bufferfly/tags/MySQL/index.html","fc17c9a8df1dedc8f6945144ddbc4953"],["/bufferfly/tags/SQL技巧/index.html","a871bde2b5e8c6fc6f646ef8aaae3973"],["/bufferfly/tags/SpringBoot/index.html","d332d8fa7d7cccccb38f79d76c92c83a"],["/bufferfly/tags/index.html","9ca228ba07f22650ce7cd0151711aa05"],["/bufferfly/tags/博客园/index.html","a8c93e9ff6b8e4527b7074d6ebf64d83"],["/bufferfly/tags/博客美化/index.html","6aef51161cbfef9c1f2eac99ee0a86e8"],["/bufferfly/tags/生活杂谈/index.html","c2cce936548fc766224f064b8febb038"],["/bufferfly/tags/练手项目/index.html","dff929fc734d15669dbb7d5f0e233013"],["/bufferfly/video/index.html","9125a4fe5b35b2e98695e4854e038197"],["/bufferfly/风景/index.html","1ce9cbfd3d7f1b0b204e962d637871be"]];
var cacheName = 'sw-precache-v3--' + (self.registration ? self.registration.scope : '');
var firstRegister = 1; // 默认1是首次安装SW, 0是SW更新
var ignoreUrlParametersMatching = [/^utm_/];
var addDirectoryIndex = function (originalUrl, index) {
var url = new URL(originalUrl);
if (url.pathname.slice(-1) === '/') {
url.pathname += index;
}
return url.toString();
};
var cleanResponse = function (originalResponse) {
// 如果没有重定向响应,不需干啥
if (!originalResponse.redirected) {
return Promise.resolve(originalResponse);
}
// Firefox 50 及以下不知处 Response.body 流, 所以我们需要读取整个body以blob形式返回。
var bodyPromise = 'body' in originalResponse ?
Promise.resolve(originalResponse.body) :
originalResponse.blob();
return bodyPromise.then(function (body) {
// new Response() 可同时支持 stream or Blob.
return new Response(body, {
headers: originalResponse.headers,
status: originalResponse.status,
statusText: originalResponse.statusText
});
});
};
var createCacheKey = function (originalUrl, paramName, paramValue,
dontCacheBustUrlsMatching) {
// 创建一个新的URL对象,避免影响原始URL
var url = new URL(originalUrl);
// 如果 dontCacheBustUrlsMatching 值没有设置,或是没有匹配到,将值拼接到url.serach后
if (!dontCacheBustUrlsMatching ||
!(url.pathname.match(dontCacheBustUrlsMatching))) {
url.search += (url.search ? '&' : '') +
encodeURIComponent(paramName) + '=' + encodeURIComponent(paramValue);
}
return url.toString();
};
var isPathWhitelisted = function (whitelist, absoluteUrlString) {
// 如果 whitelist 是空数组,则认为全部都在白名单内
if (whitelist.length === 0) {
return true;
}
// 否则逐个匹配正则匹配并返回
var path = (new URL(absoluteUrlString)).pathname;
return whitelist.some(function (whitelistedPathRegex) {
return path.match(whitelistedPathRegex);
});
};
var stripIgnoredUrlParameters = function (originalUrl,
ignoreUrlParametersMatching) {
var url = new URL(originalUrl);
// 移除 hash; 查看 https://github.com/GoogleChrome/sw-precache/issues/290
url.hash = '';
url.search = url.search.slice(1) // 是否包含 '?'
.split('&') // 分割成数组 'key=value' 的形式
.map(function (kv) {
return kv.split('='); // 分割每个 'key=value' 字符串成 [key, value] 形式
})
.filter(function (kv) {
return ignoreUrlParametersMatching.every(function (ignoredRegex) {
return !ignoredRegex.test(kv[0]); // 如果 key 没有匹配到任何忽略参数正则,就 Return true
});
})
.map(function (kv) {
return kv.join('='); // 重新把 [key, value] 格式转换为 'key=value' 字符串
})
.join('&'); // 将所有参数 'key=value' 以 '&' 拼接
return url.toString();
};
var addDirectoryIndex = function (originalUrl, index) {
var url = new URL(originalUrl);
if (url.pathname.slice(-1) === '/') {
url.pathname += index;
}
return url.toString();
};
var hashParamName = '_sw-precache';
var urlsToCacheKeys = new Map(
precacheConfig.map(function (item) {
var relativeUrl = item[0];
var hash = item[1];
var absoluteUrl = new URL(relativeUrl, self.location);
var cacheKey = createCacheKey(absoluteUrl, hashParamName, hash, false);
return [absoluteUrl.toString(), cacheKey];
})
);
function setOfCachedUrls(cache) {
return cache.keys().then(function (requests) {
// 如果原cacheName中没有缓存任何收,就默认是首次安装,否则认为是SW更新
if (requests && requests.length > 0) {
firstRegister = 0; // SW更新
}
return requests.map(function (request) {
return request.url;
});
}).then(function (urls) {
return new Set(urls);
});
}
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(cacheName).then(function (cache) {
return setOfCachedUrls(cache).then(function (cachedUrls) {
return Promise.all(
Array.from(urlsToCacheKeys.values()).map(function (cacheKey) {
// 如果缓存中没有匹配到cacheKey,添加进去
if (!cachedUrls.has(cacheKey)) {
var request = new Request(cacheKey, { credentials: 'same-origin' });
return fetch(request).then(function (response) {
// 只要返回200才能继续,否则直接抛错
if (!response.ok) {
throw new Error('Request for ' + cacheKey + ' returned a ' +
'response with status ' + response.status);
}
return cleanResponse(response).then(function (responseToCache) {
return cache.put(cacheKey, responseToCache);
});
});
}
})
);
});
})
.then(function () {
// 强制 SW 状态 installing -> activate
return self.skipWaiting();
})
);
});
self.addEventListener('activate', function (event) {
var setOfExpectedUrls = new Set(urlsToCacheKeys.values());
event.waitUntil(
caches.open(cacheName).then(function (cache) {
return cache.keys().then(function (existingRequests) {
return Promise.all(
existingRequests.map(function (existingRequest) {
// 删除原缓存中相同键值内容
if (!setOfExpectedUrls.has(existingRequest.url)) {
return cache.delete(existingRequest);
}
})
);
});
}).then(function () {
return self.clients.claim();
}).then(function () {
// 如果是首次安装 SW 时, 不发送更新消息(是否是首次安装,通过指定cacheName 中是否有缓存信息判断)
// 如果不是首次安装,则是内容有更新,需要通知页面重载更新
if (!firstRegister) {
return self.clients.matchAll()
.then(function (clients) {
if (clients && clients.length) {
clients.forEach(function (client) {
client.postMessage('sw.update');
})
}
})
}
})
);
});
self.addEventListener('fetch', function (event) {
if (event.request.method === 'GET') {
// 是否应该 event.respondWith(),需要我们逐步的判断
// 而且也方便了后期做特殊的特殊
var shouldRespond;
// 首先去除已配置的忽略参数及hash
// 查看缓存简直中是否包含该请求,包含就将shouldRespond 设为true
var url = stripIgnoredUrlParameters(event.request.url, ignoreUrlParametersMatching);
shouldRespond = urlsToCacheKeys.has(url);
// 如果 shouldRespond 是 false, 我们在url后默认增加 'index.html'
// (或者是你在配置文件中自行配置的 directoryIndex 参数值),继续查找缓存列表
var directoryIndex = 'index.html';
if (!shouldRespond && directoryIndex) {
url = addDirectoryIndex(url, directoryIndex);
shouldRespond = urlsToCacheKeys.has(url);
}
// 如果 shouldRespond 仍是 false,检查是否是navigation
// request, 如果是的话,判断是否能与 navigateFallbackWhitelist 正则列表匹配
var navigateFallback = '';
if (!shouldRespond &&
navigateFallback &&
(event.request.mode === 'navigate') &&
isPathWhitelisted([], event.request.url)
) {
url = new URL(navigateFallback, self.location).toString();
shouldRespond = urlsToCacheKeys.has(url);
}
// 如果 shouldRespond 被置为 true
// 则 event.respondWith()匹配缓存返回结果,匹配不成就直接请求.
if (shouldRespond) {
event.respondWith(
caches.open(cacheName).then(function (cache) {
return cache.match(urlsToCacheKeys.get(url)).then(function (response) {
if (response) {
return response;
}
throw Error('The cached response that was expected is missing.');
});
}).catch(function (e) {
// 如果捕获到异常错误,直接返回 fetch() 请求资源
console.warn('Couldn\'t serve response for "%s" from cache: %O', event.request.url, e);
return fetch(event.request);
})
);
}
}
});
// *** Start of auto-included sw-toolbox code. ***
/*
Copyright 2016 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.toolbox=e()}}(function(){return function e(t,n,r){function o(c,s){if(!n[c]){if(!t[c]){var a="function"==typeof require&&require;if(!s&&a)return a(c,!0);if(i)return i(c,!0);var u=new Error("Cannot find module '"+c+"'");throw u.code="MODULE_NOT_FOUND",u}var f=n[c]={exports:{}};t[c][0].call(f.exports,function(e){var n=t[c][1][e];return o(n?n:e)},f,f.exports,e,t,n,r)}return n[c].exports}for(var i="function"==typeof require&&require,c=0;c<r.length;c++)o(r[c]);return o}({1:[function(e,t,n){"use strict";function r(e,t){t=t||{};var n=t.debug||m.debug;n&&console.log("[sw-toolbox] "+e)}function o(e){var t;return e&&e.cache&&(t=e.cache.name),t=t||m.cache.name,caches.open(t)}function i(e,t){t=t||{};var n=t.successResponses||m.successResponses;return fetch(e.clone()).then(function(r){return"GET"===e.method&&n.test(r.status)&&o(t).then(function(n){n.put(e,r).then(function(){var r=t.cache||m.cache;(r.maxEntries||r.maxAgeSeconds)&&r.name&&c(e,n,r)})}),r.clone()})}function c(e,t,n){var r=s.bind(null,e,t,n);d=d?d.then(r):r()}function s(e,t,n){var o=e.url,i=n.maxAgeSeconds,c=n.maxEntries,s=n.name,a=Date.now();return r("Updating LRU order for "+o+". Max entries is "+c+", max age is "+i),g.getDb(s).then(function(e){return g.setTimestampForUrl(e,o,a)}).then(function(e){return g.expireEntries(e,c,i,a)}).then(function(e){r("Successfully updated IDB.");var n=e.map(function(e){return t.delete(e)});return Promise.all(n).then(function(){r("Done with cache cleanup.")})}).catch(function(e){r(e)})}function a(e,t,n){return r("Renaming cache: ["+e+"] to ["+t+"]",n),caches.delete(t).then(function(){return Promise.all([caches.open(e),caches.open(t)]).then(function(t){var n=t[0],r=t[1];return n.keys().then(function(e){return Promise.all(e.map(function(e){return n.match(e).then(function(t){return r.put(e,t)})}))}).then(function(){return caches.delete(e)})})})}function u(e,t){return o(t).then(function(t){return t.add(e)})}function f(e,t){return o(t).then(function(t){return t.delete(e)})}function h(e){e instanceof Promise||p(e),m.preCacheItems=m.preCacheItems.concat(e)}function p(e){var t=Array.isArray(e);if(t&&e.forEach(function(e){"string"==typeof e||e instanceof Request||(t=!1)}),!t)throw new TypeError("The precache method expects either an array of strings and/or Requests or a Promise that resolves to an array of strings and/or Requests.");return e}function l(e,t,n){if(!e)return!1;if(t){var r=e.headers.get("date");if(r){var o=new Date(r);if(o.getTime()+1e3*t<n)return!1}}return!0}var d,m=e("./options"),g=e("./idb-cache-expiration");t.exports={debug:r,fetchAndCache:i,openCache:o,renameCache:a,cache:u,uncache:f,precache:h,validatePrecacheInput:p,isResponseFresh:l}},{"./idb-cache-expiration":2,"./options":4}],2:[function(e,t,n){"use strict";function r(e){return new Promise(function(t,n){var r=indexedDB.open(u+e,f);r.onupgradeneeded=function(){var e=r.result.createObjectStore(h,{keyPath:p});e.createIndex(l,l,{unique:!1})},r.onsuccess=function(){t(r.result)},r.onerror=function(){n(r.error)}})}function o(e){return e in d||(d[e]=r(e)),d[e]}function i(e,t,n){return new Promise(function(r,o){var i=e.transaction(h,"readwrite"),c=i.objectStore(h);c.put({url:t,timestamp:n}),i.oncomplete=function(){r(e)},i.onabort=function(){o(i.error)}})}function c(e,t,n){return t?new Promise(function(r,o){var i=1e3*t,c=[],s=e.transaction(h,"readwrite"),a=s.objectStore(h),u=a.index(l);u.openCursor().onsuccess=function(e){var t=e.target.result;if(t&&n-i>t.value[l]){var r=t.value[p];c.push(r),a.delete(r),t.continue()}},s.oncomplete=function(){r(c)},s.onabort=o}):Promise.resolve([])}function s(e,t){return t?new Promise(function(n,r){var o=[],i=e.transaction(h,"readwrite"),c=i.objectStore(h),s=c.index(l),a=s.count();s.count().onsuccess=function(){var e=a.result;e>t&&(s.openCursor().onsuccess=function(n){var r=n.target.result;if(r){var i=r.value[p];o.push(i),c.delete(i),e-o.length>t&&r.continue()}})},i.oncomplete=function(){n(o)},i.onabort=r}):Promise.resolve([])}function a(e,t,n,r){return c(e,n,r).then(function(n){return s(e,t).then(function(e){return n.concat(e)})})}var u="sw-toolbox-",f=1,h="store",p="url",l="timestamp",d={};t.exports={getDb:o,setTimestampForUrl:i,expireEntries:a}},{}],3:[function(e,t,n){"use strict";function r(e){var t=a.match(e.request);t?e.respondWith(t(e.request)):a.default&&"GET"===e.request.method&&0===e.request.url.indexOf("http")&&e.respondWith(a.default(e.request))}function o(e){s.debug("activate event fired");var t=u.cache.name+"$$$inactive$$$";e.waitUntil(s.renameCache(t,u.cache.name))}function i(e){return e.reduce(function(e,t){return e.concat(t)},[])}function c(e){var t=u.cache.name+"$$$inactive$$$";s.debug("install event fired"),s.debug("creating cache ["+t+"]"),e.waitUntil(s.openCache({cache:{name:t}}).then(function(e){return Promise.all(u.preCacheItems).then(i).then(s.validatePrecacheInput).then(function(t){return s.debug("preCache list: "+(t.join(", ")||"(none)")),e.addAll(t)})}))}e("serviceworker-cache-polyfill");var s=e("./helpers"),a=e("./router"),u=e("./options");t.exports={fetchListener:r,activateListener:o,installListener:c}},{"./helpers":1,"./options":4,"./router":6,"serviceworker-cache-polyfill":16}],4:[function(e,t,n){"use strict";var r;r=self.registration?self.registration.scope:self.scope||new URL("./",self.location).href,t.exports={cache:{name:"$$$toolbox-cache$$$"+r+"$$$",maxAgeSeconds:null,maxEntries:null},debug:!1,networkTimeoutSeconds:null,preCacheItems:[],successResponses:/^0|([123]\d\d)|(40[14567])|410$/}},{}],5:[function(e,t,n){"use strict";var r=new URL("./",self.location),o=r.pathname,i=e("path-to-regexp"),c=function(e,t,n,r){t instanceof RegExp?this.fullUrlRegExp=t:(0!==t.indexOf("/")&&(t=o+t),this.keys=[],this.regexp=i(t,this.keys)),this.method=e,this.options=r,this.handler=n};c.prototype.makeHandler=function(e){var t;if(this.regexp){var n=this.regexp.exec(e);t={},this.keys.forEach(function(e,r){t[e.name]=n[r+1]})}return function(e){return this.handler(e,t,this.options)}.bind(this)},t.exports=c},{"path-to-regexp":15}],6:[function(e,t,n){"use strict";function r(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}var o=e("./route"),i=e("./helpers"),c=function(e,t){for(var n=e.entries(),r=n.next(),o=[];!r.done;){var i=new RegExp(r.value[0]);i.test(t)&&o.push(r.value[1]),r=n.next()}return o},s=function(){this.routes=new Map,this.routes.set(RegExp,new Map),this.default=null};["get","post","put","delete","head","any"].forEach(function(e){s.prototype[e]=function(t,n,r){return this.add(e,t,n,r)}}),s.prototype.add=function(e,t,n,c){c=c||{};var s;t instanceof RegExp?s=RegExp:(s=c.origin||self.location.origin,s=s instanceof RegExp?s.source:r(s)),e=e.toLowerCase();var a=new o(e,t,n,c);this.routes.has(s)||this.routes.set(s,new Map);var u=this.routes.get(s);u.has(e)||u.set(e,new Map);var f=u.get(e),h=a.regexp||a.fullUrlRegExp;f.has(h.source)&&i.debug('"'+t+'" resolves to same regex as existing route.'),f.set(h.source,a)},s.prototype.matchMethod=function(e,t){var n=new URL(t),r=n.origin,o=n.pathname;return this._match(e,c(this.routes,r),o)||this._match(e,[this.routes.get(RegExp)],t)},s.prototype._match=function(e,t,n){if(0===t.length)return null;for(var r=0;r<t.length;r++){var o=t[r],i=o&&o.get(e.toLowerCase());if(i){var s=c(i,n);if(s.length>0)return s[0].makeHandler(n)}}return null},s.prototype.match=function(e){return this.matchMethod(e.method,e.url)||this.matchMethod("any",e.url)},t.exports=new s},{"./helpers":1,"./route":5}],7:[function(e,t,n){"use strict";function r(e,t,n){return n=n||{},i.debug("Strategy: cache first ["+e.url+"]",n),i.openCache(n).then(function(t){return t.match(e).then(function(t){var r=n.cache||o.cache,c=Date.now();return i.isResponseFresh(t,r.maxAgeSeconds,c)?t:i.fetchAndCache(e,n)})})}var o=e("../options"),i=e("../helpers");t.exports=r},{"../helpers":1,"../options":4}],8:[function(e,t,n){"use strict";function r(e,t,n){return n=n||{},i.debug("Strategy: cache only ["+e.url+"]",n),i.openCache(n).then(function(t){return t.match(e).then(function(e){var t=n.cache||o.cache,r=Date.now();if(i.isResponseFresh(e,t.maxAgeSeconds,r))return e})})}var o=e("../options"),i=e("../helpers");t.exports=r},{"../helpers":1,"../options":4}],9:[function(e,t,n){"use strict";function r(e,t,n){return o.debug("Strategy: fastest ["+e.url+"]",n),new Promise(function(r,c){var s=!1,a=[],u=function(e){a.push(e.toString()),s?c(new Error('Both cache and network failed: "'+a.join('", "')+'"')):s=!0},f=function(e){e instanceof Response?r(e):u("No result returned")};o.fetchAndCache(e.clone(),n).then(f,u),i(e,t,n).then(f,u)})}var o=e("../helpers"),i=e("./cacheOnly");t.exports=r},{"../helpers":1,"./cacheOnly":8}],10:[function(e,t,n){t.exports={networkOnly:e("./networkOnly"),networkFirst:e("./networkFirst"),cacheOnly:e("./cacheOnly"),cacheFirst:e("./cacheFirst"),fastest:e("./fastest")}},{"./cacheFirst":7,"./cacheOnly":8,"./fastest":9,"./networkFirst":11,"./networkOnly":12}],11:[function(e,t,n){"use strict";function r(e,t,n){n=n||{};var r=n.successResponses||o.successResponses,c=n.networkTimeoutSeconds||o.networkTimeoutSeconds;return i.debug("Strategy: network first ["+e.url+"]",n),i.openCache(n).then(function(t){var s,a,u=[];if(c){var f=new Promise(function(r){s=setTimeout(function(){t.match(e).then(function(e){var t=n.cache||o.cache,c=Date.now(),s=t.maxAgeSeconds;i.isResponseFresh(e,s,c)&&r(e)})},1e3*c)});u.push(f)}var h=i.fetchAndCache(e,n).then(function(e){if(s&&clearTimeout(s),r.test(e.status))return e;throw i.debug("Response was an HTTP error: "+e.statusText,n),a=e,new Error("Bad response")}).catch(function(r){return i.debug("Network or response error, fallback to cache ["+e.url+"]",n),t.match(e).then(function(e){if(e)return e;if(a)return a;throw r})});return u.push(h),Promise.race(u)})}var o=e("../options"),i=e("../helpers");t.exports=r},{"../helpers":1,"../options":4}],12:[function(e,t,n){"use strict";function r(e,t,n){return o.debug("Strategy: network only ["+e.url+"]",n),fetch(e)}var o=e("../helpers");t.exports=r},{"../helpers":1}],13:[function(e,t,n){"use strict";var r=e("./options"),o=e("./router"),i=e("./helpers"),c=e("./strategies"),s=e("./listeners");i.debug("Service Worker Toolbox is loading"),self.addEventListener("install",s.installListener),self.addEventListener("activate",s.activateListener),self.addEventListener("fetch",s.fetchListener),t.exports={networkOnly:c.networkOnly,networkFirst:c.networkFirst,cacheOnly:c.cacheOnly,cacheFirst:c.cacheFirst,fastest:c.fastest,router:o,options:r,cache:i.cache,uncache:i.uncache,precache:i.precache}},{"./helpers":1,"./listeners":3,"./options":4,"./router":6,"./strategies":10}],14:[function(e,t,n){t.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},{}],15:[function(e,t,n){function r(e,t){for(var n,r=[],o=0,i=0,c="",s=t&&t.delimiter||"/";null!=(n=x.exec(e));){var f=n[0],h=n[1],p=n.index;if(c+=e.slice(i,p),i=p+f.length,h)c+=h[1];else{var l=e[i],d=n[2],m=n[3],g=n[4],v=n[5],w=n[6],y=n[7];c&&(r.push(c),c="");var b=null!=d&&null!=l&&l!==d,E="+"===w||"*"===w,R="?"===w||"*"===w,k=n[2]||s,$=g||v;r.push({name:m||o++,prefix:d||"",delimiter:k,optional:R,repeat:E,partial:b,asterisk:!!y,pattern:$?u($):y?".*":"[^"+a(k)+"]+?"})}}return i<e.length&&(c+=e.substr(i)),c&&r.push(c),r}function o(e,t){return s(r(e,t))}function i(e){return encodeURI(e).replace(/[\/?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function c(e){return encodeURI(e).replace(/[?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function s(e){for(var t=new Array(e.length),n=0;n<e.length;n++)"object"==typeof e[n]&&(t[n]=new RegExp("^(?:"+e[n].pattern+")$"));return function(n,r){for(var o="",s=n||{},a=r||{},u=a.pretty?i:encodeURIComponent,f=0;f<e.length;f++){var h=e[f];if("string"!=typeof h){var p,l=s[h.name];if(null==l){if(h.optional){h.partial&&(o+=h.prefix);continue}throw new TypeError('Expected "'+h.name+'" to be defined')}if(v(l)){if(!h.repeat)throw new TypeError('Expected "'+h.name+'" to not repeat, but received `'+JSON.stringify(l)+"`");if(0===l.length){if(h.optional)continue;throw new TypeError('Expected "'+h.name+'" to not be empty')}for(var d=0;d<l.length;d++){if(p=u(l[d]),!t[f].test(p))throw new TypeError('Expected all "'+h.name+'" to match "'+h.pattern+'", but received `'+JSON.stringify(p)+"`");o+=(0===d?h.prefix:h.delimiter)+p}}else{if(p=h.asterisk?c(l):u(l),!t[f].test(p))throw new TypeError('Expected "'+h.name+'" to match "'+h.pattern+'", but received "'+p+'"');o+=h.prefix+p}}else o+=h}return o}}function a(e){return e.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function u(e){return e.replace(/([=!:$\/()])/g,"\\$1")}function f(e,t){return e.keys=t,e}function h(e){return e.sensitive?"":"i"}function p(e,t){var n=e.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)t.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return f(e,t)}function l(e,t,n){for(var r=[],o=0;o<e.length;o++)r.push(g(e[o],t,n).source);var i=new RegExp("(?:"+r.join("|")+")",h(n));return f(i,t)}function d(e,t,n){return m(r(e,n),t,n)}function m(e,t,n){v(t)||(n=t||n,t=[]),n=n||{};for(var r=n.strict,o=n.end!==!1,i="",c=0;c<e.length;c++){var s=e[c];if("string"==typeof s)i+=a(s);else{var u=a(s.prefix),p="(?:"+s.pattern+")";t.push(s),s.repeat&&(p+="(?:"+u+p+")*"),p=s.optional?s.partial?u+"("+p+")?":"(?:"+u+"("+p+"))?":u+"("+p+")",i+=p}}var l=a(n.delimiter||"/"),d=i.slice(-l.length)===l;return r||(i=(d?i.slice(0,-l.length):i)+"(?:"+l+"(?=$))?"),i+=o?"$":r&&d?"":"(?="+l+"|$)",f(new RegExp("^"+i,h(n)),t)}function g(e,t,n){return v(t)||(n=t||n,t=[]),n=n||{},e instanceof RegExp?p(e,t):v(e)?l(e,t,n):d(e,t,n)}var v=e("isarray");t.exports=g,t.exports.parse=r,t.exports.compile=o,t.exports.tokensToFunction=s,t.exports.tokensToRegExp=m;var x=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g")},{isarray:14}],16:[function(e,t,n){!function(){var e=Cache.prototype.addAll,t=navigator.userAgent.match(/(Firefox|Chrome)\/(\d+\.)/);if(t)var n=t[1],r=parseInt(t[2]);e&&(!t||"Firefox"===n&&r>=46||"Chrome"===n&&r>=50)||(Cache.prototype.addAll=function(e){function t(e){this.name="NetworkError",this.code=19,this.message=e}var n=this;return t.prototype=Object.create(Error.prototype),Promise.resolve().then(function(){if(arguments.length<1)throw new TypeError;return e=e.map(function(e){return e instanceof Request?e:String(e)}),Promise.all(e.map(function(e){"string"==typeof e&&(e=new Request(e));var n=new URL(e.url).protocol;if("http:"!==n&&"https:"!==n)throw new t("Invalid scheme");return fetch(e.clone())}))}).then(function(r){if(r.some(function(e){return!e.ok}))throw new t("Incorrect response status");return Promise.all(r.map(function(t,r){return n.put(e[r],t)}))}).then(function(){})},Cache.prototype.add=function(e){return this.addAll([e])})}()},{}]},{},[13])(13)});
// *** End of auto-included sw-toolbox code. ***
// Runtime cache 配置转换后的 toolbox 代码.
toolbox.router.get("/*", toolbox.cacheFirst, {"origin":"unpkg.com"});
toolbox.router.get("/npm/*", toolbox.cacheFirst, {"origin":"cdn.jsdelivr.net"});
/* eslint-enable */
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化