jekyll-pwa-plugin-fork 2.1.1.pre.fork2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/jekyll-pwa-plugin-fork.rb +185 -0
- data/lib/vendor/workbox-v3.6.3/workbox-background-sync.dev.js +593 -0
- data/lib/vendor/workbox-v3.6.3/workbox-background-sync.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-background-sync.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-background-sync.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.dev.js +395 -0
- data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.dev.js +740 -0
- data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.dev.js +236 -0
- data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-core.dev.js +1736 -0
- data/lib/vendor/workbox-v3.6.3/workbox-core.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-core.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-core.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.dev.js +255 -0
- data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.dev.js +159 -0
- data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-precaching.dev.js +1171 -0
- data/lib/vendor/workbox-v3.6.3/workbox-precaching.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-precaching.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-precaching.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-range-requests.dev.js +299 -0
- data/lib/vendor/workbox-v3.6.3/workbox-range-requests.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-range-requests.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-range-requests.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-routing.dev.js +863 -0
- data/lib/vendor/workbox-v3.6.3/workbox-routing.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-routing.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-routing.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-strategies.dev.js +1172 -0
- data/lib/vendor/workbox-v3.6.3/workbox-strategies.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-strategies.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-strategies.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-streams.dev.js +380 -0
- data/lib/vendor/workbox-v3.6.3/workbox-streams.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-streams.prod.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-streams.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.6.3/workbox-sw.js +3 -0
- data/lib/vendor/workbox-v3.6.3/workbox-sw.js.map +1 -0
- metadata +108 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"mappings":"","sources":["packages/workbox-routing/browser.mjs"],"sourcesContent":["this.workbox = this.workbox || {};\nthis.workbox.routing = (function (assert_mjs,logger_mjs,WorkboxError_mjs,getFriendlyURL_mjs,cacheNames_mjs) {\n 'use strict';\n\n try {\n self.workbox.v['workbox:routing:3.6.3'] = 1;\n } catch (e) {} // eslint-disable-line\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * The default HTTP method, 'GET', used when there's no specific method\n * configured for a route.\n *\n * @type {string}\n *\n * @private\n */\n const defaultMethod = 'GET';\n\n /**\n * The list of valid HTTP methods associated with requests that could be routed.\n *\n * @type {Array<string>}\n *\n * @private\n */\n const validMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'];\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * @param {function()|Object} handler Either a function, or an object with a\n * 'handle' method.\n * @return {Object} An object with a handle method.\n *\n * @private\n */\n var normalizeHandler = (handler => {\n if (handler && typeof handler === 'object') {\n {\n assert_mjs.assert.hasMethod(handler, 'handle', {\n moduleName: 'workbox-routing',\n className: 'Route',\n funcName: 'constructor',\n paramName: 'handler'\n });\n }\n return handler;\n } else {\n {\n assert_mjs.assert.isType(handler, 'function', {\n moduleName: 'workbox-routing',\n className: 'Route',\n funcName: 'constructor',\n paramName: 'handler'\n });\n }\n return { handle: handler };\n }\n });\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * A `Route` consists of a pair of callback functions, \"match\" and \"handler\".\n * The \"match\" callback determine if a route should be used to \"handle\" a\n * request by returning a non-falsy value if it can. The \"handler\" callback\n * is called when there is a match and should return a Promise that resolves\n * to a `Response`.\n *\n * @memberof workbox.routing\n */\n class Route {\n /**\n * Constructor for Route class.\n *\n * @param {workbox.routing.Route~matchCallback} match\n * A callback function that determines whether the route matches a given\n * `fetch` event by returning a non-falsy value.\n * @param {workbox.routing.Route~handlerCallback} handler A callback\n * function that returns a Promise resolving to a Response.\n * @param {string} [method='GET'] The HTTP method to match the Route\n * against.\n */\n constructor(match, handler, method) {\n {\n assert_mjs.assert.isType(match, 'function', {\n moduleName: 'workbox-routing',\n className: 'Route',\n funcName: 'constructor',\n paramName: 'match'\n });\n\n if (method) {\n assert_mjs.assert.isOneOf(method, validMethods, { paramName: 'method' });\n }\n }\n\n // These values are referenced directly by Router so cannot be\n // altered by minifification.\n this.handler = normalizeHandler(handler);\n this.match = match;\n this.method = method || defaultMethod;\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * RegExpRoute makes it easy to create a regular expression based\n * [Route]{@link workbox.routing.Route}.\n *\n * For same-origin requests the RegExp only needs to match part of the URL. For\n * requests against third-party servers, you must define a RegExp that matches\n * the start of the URL.\n *\n * [See the module docs for info.]{@link https://developers.google.com/web/tools/workbox/modules/workbox-routing}\n *\n * @memberof workbox.routing\n * @extends workbox.routing.Route\n */\n class RegExpRoute extends Route {\n /**\n * If the regulard expression contains\n * [capture groups]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references},\n * th ecaptured values will be passed to the\n * [handler's]{@link workbox.routing.Route~handlerCallback} `params`\n * argument.\n *\n * @param {RegExp} regExp The regular expression to match against URLs.\n * @param {workbox.routing.Route~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n * @param {string} [method='GET'] The HTTP method to match the Route\n * against.\n */\n constructor(regExp, handler, method) {\n {\n assert_mjs.assert.isInstance(regExp, RegExp, {\n moduleName: 'workbox-routing',\n className: 'RegExpRoute',\n funcName: 'constructor',\n paramName: 'pattern'\n });\n }\n\n const match = ({ url }) => {\n const result = regExp.exec(url.href);\n\n // Return null immediately if there's no match.\n if (!result) {\n return null;\n }\n\n // Require that the match start at the first character in the URL string\n // if it's a cross-origin request.\n // See https://github.com/GoogleChrome/workbox/issues/281 for the context\n // behind this behavior.\n if (url.origin !== location.origin && result.index !== 0) {\n {\n logger_mjs.logger.debug(`The regular expression '${regExp}' only partially matched ` + `against the cross-origin URL '${url}'. RegExpRoute's will only ` + `handle cross-origin requests if they match the entire URL.`);\n }\n\n return null;\n }\n\n // If the route matches, but there aren't any capture groups defined, then\n // this will return [], which is truthy and therefore sufficient to\n // indicate a match.\n // If there are capture groups, then it will return their values.\n return result.slice(1);\n };\n\n super(match, handler, method);\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * The Router can be used to process a FetchEvent through one or more\n * [Routes]{@link workbox.routing.Route} responding with a Request if\n * a matching route exists.\n *\n * If no route matches a given a request, the Router will use a \"default\"\n * handler if one is defined.\n *\n * Should the matching Route throw an error, the Router will use a \"catch\"\n * handler if one is defined to gracefully deal with issues and respond with a\n * Request.\n *\n * If a request matches multiple routes, the **earliest** registered route will\n * be used to respond to the request.\n *\n * @memberof workbox.routing\n */\n class Router {\n /**\n * Initializes a new Router.\n */\n constructor() {\n // _routes will contain a mapping of HTTP method name ('GET', etc.) to an\n // array of all the corresponding Route instances that are registered.\n this._routes = new Map();\n }\n\n /**\n * Apply the routing rules to a FetchEvent object to get a Response from an\n * appropriate Route's handler.\n *\n * @param {FetchEvent} event The event from a service worker's 'fetch' event\n * listener.\n * @return {Promise<Response>|undefined} A promise is returned if a\n * registered route can handle the FetchEvent's request. If there is no\n * matching route and there's no `defaultHandler`, `undefined` is returned.\n */\n handleRequest(event) {\n {\n assert_mjs.assert.isInstance(event, FetchEvent, {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'handleRequest',\n paramName: 'event'\n });\n }\n\n const url = new URL(event.request.url);\n if (!url.protocol.startsWith('http')) {\n {\n logger_mjs.logger.debug(`Workbox Router only supports URLs that start with 'http'.`);\n }\n return;\n }\n\n let route = null;\n let handler = null;\n let params = null;\n let debugMessages = [];\n\n const result = this._findHandlerAndParams(event, url);\n handler = result.handler;\n params = result.params;\n route = result.route;\n {\n if (handler) {\n debugMessages.push([`Found a route to handle this request:`, route]);\n\n if (params) {\n debugMessages.push([`Passing the following params to the route's handler:`, params]);\n }\n }\n }\n\n // If we don't have a handler because there was no matching route, then\n // fall back to defaultHandler if that's defined.\n if (!handler && this._defaultHandler) {\n {\n debugMessages.push(`Failed to find a matching route. Falling ` + `back to the default handler.`);\n\n // This is used for debugging in logs in the case of an error.\n route = '[Default Handler]';\n }\n handler = this._defaultHandler;\n }\n\n if (!handler) {\n {\n // No handler so Workbox will do nothing. If logs is set of debug\n // i.e. verbose, we should print out this information.\n logger_mjs.logger.debug(`No route found for: ${getFriendlyURL_mjs.getFriendlyURL(url)}`);\n }\n return;\n }\n\n {\n // We have a handler, meaning Workbox is going to handle the route.\n // print the routing details to the console.\n logger_mjs.logger.groupCollapsed(`Router is responding to: ${getFriendlyURL_mjs.getFriendlyURL(url)}`);\n debugMessages.forEach(msg => {\n if (Array.isArray(msg)) {\n logger_mjs.logger.log(...msg);\n } else {\n logger_mjs.logger.log(msg);\n }\n });\n\n // The Request and Response objects contains a great deal of information,\n // hide it under a group in case developers want to see it.\n logger_mjs.logger.groupCollapsed(`View request details here.`);\n logger_mjs.logger.unprefixed.log(event.request);\n logger_mjs.logger.groupEnd();\n\n logger_mjs.logger.groupEnd();\n }\n\n // Wrap in try and catch in case the handle method throws a synchronous\n // error. It should still callback to the catch handler.\n let responsePromise;\n try {\n responsePromise = handler.handle({ url, event, params });\n } catch (err) {\n responsePromise = Promise.reject(err);\n }\n\n if (responsePromise && this._catchHandler) {\n responsePromise = responsePromise.catch(err => {\n {\n // Still include URL here as it will be async from the console group\n // and may not make sense without the URL\n logger_mjs.logger.groupCollapsed(`Error thrown when responding to: ` + ` ${getFriendlyURL_mjs.getFriendlyURL(url)}. Falling back to Catch Handler.`);\n logger_mjs.logger.unprefixed.error(`Error thrown by:`, route);\n logger_mjs.logger.unprefixed.error(err);\n logger_mjs.logger.groupEnd();\n }\n return this._catchHandler.handle({ url, event, err });\n });\n }\n\n return responsePromise;\n }\n\n /**\n * Checks the incoming `event.request` against the registered routes, and if\n * there's a match, returns the corresponding handler along with any params\n * generated by the match.\n *\n * @param {FetchEvent} event\n * @param {URL} url\n * @return {Object} Returns an object with `handler` and `params` properties.\n * They are populated if a matching route was found or `undefined` otherwise.\n *\n * @private\n */\n _findHandlerAndParams(event, url) {\n const routes = this._routes.get(event.request.method) || [];\n for (const route of routes) {\n let matchResult = route.match({ url, event });\n if (matchResult) {\n if (Array.isArray(matchResult) && matchResult.length === 0) {\n // Instead of passing an empty array in as params, use undefined.\n matchResult = undefined;\n } else if (matchResult.constructor === Object && Object.keys(matchResult).length === 0 || matchResult === true) {\n // Instead of passing an empty object in as params, use undefined.\n matchResult = undefined;\n }\n\n // Break out of the loop and return the appropriate values as soon as\n // we have a match.\n return {\n route,\n params: matchResult,\n handler: route.handler\n };\n }\n }\n\n // If we didn't have a match, then return undefined values.\n return { handler: undefined, params: undefined };\n }\n\n /**\n * Define a default `handler` that's called when no routes explicitly\n * match the incoming request.\n *\n * Without a default handler, unmatched requests will go against the\n * network as if there were no service worker present.\n *\n * @param {workbox.routing.Route~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n */\n setDefaultHandler(handler) {\n this._defaultHandler = normalizeHandler(handler);\n }\n\n /**\n * If a Route throws an error while handling a request, this `handler`\n * will be called and given a chance to provide a response.\n *\n * @param {workbox.routing.Route~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n */\n setCatchHandler(handler) {\n this._catchHandler = normalizeHandler(handler);\n }\n\n /**\n * Registers a route with the router.\n *\n * @param {workbox.routing.Route} route The route to register.\n */\n registerRoute(route) {\n {\n assert_mjs.assert.isType(route, 'object', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route'\n });\n\n assert_mjs.assert.hasMethod(route, 'match', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route'\n });\n\n assert_mjs.assert.isType(route.handler, 'object', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route'\n });\n\n assert_mjs.assert.hasMethod(route.handler, 'handle', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route.handler'\n });\n\n assert_mjs.assert.isType(route.method, 'string', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route.method'\n });\n }\n\n if (!this._routes.has(route.method)) {\n this._routes.set(route.method, []);\n }\n\n // Give precedence to all of the earlier routes by adding this additional\n // route to the end of the array.\n this._routes.get(route.method).push(route);\n }\n\n /**\n * Unregisters a route with the router.\n *\n * @param {workbox.routing.Route} route The route to unregister.\n */\n unregisterRoute(route) {\n if (!this._routes.has(route.method)) {\n throw new WorkboxError_mjs.WorkboxError('unregister-route-but-not-found-with-method', {\n method: route.method\n });\n }\n\n const routeIndex = this._routes.get(route.method).indexOf(route);\n if (routeIndex > -1) {\n this._routes.get(route.method).splice(routeIndex, 1);\n } else {\n throw new WorkboxError_mjs.WorkboxError('unregister-route-route-not-registered');\n }\n }\n }\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * NavigationRoute makes it easy to create a [Route]{@link\n * workbox.routing.Route} that matches for browser\n * [navigation requests]{@link https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests}.\n *\n * It will only match incoming Requests whose\n * [`mode`]{@link https://fetch.spec.whatwg.org/#concept-request-mode}\n * is set to `navigate`.\n *\n * You can optionally only apply this route to a subset of navigation requests\n * by using one or both of the `blacklist` and `whitelist` parameters.\n *\n * @memberof workbox.routing\n * @extends workbox.routing.Route\n */\n class NavigationRoute extends Route {\n /**\n * If both `blacklist` and `whiltelist` are provided, the `blacklist` will\n * take precedence and the request will not match this route.\n *\n * The regular expressions in `whitelist` and `blacklist`\n * are matched against the concatenated\n * [`pathname`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname}\n * and [`search`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search}\n * portions of the requested URL.\n *\n * @param {workbox.routing.Route~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n * @param {Object} options\n * @param {Array<RegExp>} [options.blacklist] If any of these patterns match,\n * the route will not handle the request (even if a whitelist RegExp matches).\n * @param {Array<RegExp>} [options.whitelist=[/./]] If any of these patterns\n * match the URL's pathname and search parameter, the route will handle the\n * request (assuming the blacklist doesn't match).\n */\n constructor(handler, { whitelist = [/./], blacklist = [] } = {}) {\n {\n assert_mjs.assert.isArrayOfClass(whitelist, RegExp, {\n moduleName: 'workbox-routing',\n className: 'NavigationRoute',\n funcName: 'constructor',\n paramName: 'options.whitelist'\n });\n assert_mjs.assert.isArrayOfClass(blacklist, RegExp, {\n moduleName: 'workbox-routing',\n className: 'NavigationRoute',\n funcName: 'constructor',\n paramName: 'options.blacklist'\n });\n }\n\n super((...args) => this._match(...args), handler);\n\n this._whitelist = whitelist;\n this._blacklist = blacklist;\n }\n\n /**\n * Routes match handler.\n *\n * @param {Object} options\n * @param {FetchEvent} options.event\n * @param {URL} options.url\n * @return {boolean}\n *\n * @private\n */\n _match({ event, url }) {\n if (event.request.mode !== 'navigate') {\n return false;\n }\n\n const pathnameAndSearch = url.pathname + url.search;\n\n if (this._blacklist.some(regExp => regExp.test(pathnameAndSearch))) {\n {\n logger_mjs.logger.debug(`The navigation route is not being used, since the ` + `request URL matches both the whitelist and blacklist.`);\n }\n return false;\n }\n\n if (this._whitelist.some(regExp => regExp.test(pathnameAndSearch))) {\n {\n logger_mjs.logger.debug(`The navigation route is being used.`);\n }\n return true;\n } else {\n {\n logger_mjs.logger.debug(`The navigation route is not being used, since the ` + `URL being navigated to doesn't match the whitelist.`);\n }\n }\n\n return false;\n }\n }\n\n /*\n Copyright 2017 Google Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n var publicAPI = /*#__PURE__*/Object.freeze({\n RegExpRoute: RegExpRoute,\n Route: Route,\n Router: Router,\n NavigationRoute: NavigationRoute\n });\n\n /*\n Copyright 2017 Google Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n {\n assert_mjs.assert.isSwEnv('workbox-routing');\n }\n\n /**\n * @private\n */\n class DefaultRouter extends Router {\n /**\n * Easily register a RegExp, string, or function with a caching\n * strategy to the Router.\n *\n * This method will generate a Route for you if needed and\n * call [Router.registerRoute()]{@link\n * workbox.routing.Router#registerRoute}.\n *\n * @param {\n * RegExp|\n * string|\n * workbox.routing.Route~matchCallback|\n * workbox.routing.Route\n * } capture\n * If the capture param is a `Route`, all other arguments will be ignored.\n * @param {workbox.routing.Route~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n * @param {string} [method='GET'] The HTTP method to match the Route\n * against.\n * @return {workbox.routing.Route} The generated `Route`(Useful for\n * unregistering).\n *\n * @alias workbox.routing.registerRoute\n */\n registerRoute(capture, handler, method = 'GET') {\n let route;\n\n if (typeof capture === 'string') {\n const captureUrl = new URL(capture, location);\n\n {\n if (!(capture.startsWith('/') || capture.startsWith('http'))) {\n throw new WorkboxError_mjs.WorkboxError('invalid-string', {\n moduleName: 'workbox-routing',\n className: 'DefaultRouter',\n funcName: 'registerRoute',\n paramName: 'capture'\n });\n }\n\n // We want to check if Express-style wildcards are in the pathname only.\n // TODO: Remove this log message in v4.\n const valueToCheck = capture.startsWith('http') ? captureUrl.pathname : capture;\n // See https://github.com/pillarjs/path-to-regexp#parameters\n const wildcards = '[*:?+]';\n if (valueToCheck.match(new RegExp(`${wildcards}`))) {\n logger_mjs.logger.debug(`The '$capture' parameter contains an Express-style wildcard ` + `character (${wildcards}). Strings are now always interpreted as ` + `exact matches; use a RegExp for partial or wildcard matches.`);\n }\n }\n\n const matchCallback = ({ url }) => {\n {\n if (url.pathname === captureUrl.pathname && url.origin !== captureUrl.origin) {\n logger_mjs.logger.debug(`${capture} only partially matches the cross-origin URL ` + `${url}. This route will only handle cross-origin requests ` + `if they match the entire URL.`);\n }\n }\n\n return url.href === captureUrl.href;\n };\n\n route = new Route(matchCallback, handler, method);\n } else if (capture instanceof RegExp) {\n route = new RegExpRoute(capture, handler, method);\n } else if (typeof capture === 'function') {\n route = new Route(capture, handler, method);\n } else if (capture instanceof Route) {\n route = capture;\n } else {\n throw new WorkboxError_mjs.WorkboxError('unsupported-route-type', {\n moduleName: 'workbox-routing',\n className: 'DefaultRouter',\n funcName: 'registerRoute',\n paramName: 'capture'\n });\n }\n\n super.registerRoute(route);\n return route;\n }\n\n /**\n * Register a route that will return a precached file for a navigation\n * request. This is useful for the\n * [application shell pattern]{@link https://developers.google.com/web/fundamentals/architecture/app-shell}.\n *\n * This method will generate a\n * [NavigationRoute]{@link workbox.routing.NavigationRoute}\n * and call\n * [Router.registerRoute()]{@link workbox.routing.Router#registerRoute}\n * .\n *\n * @param {string} cachedAssetUrl\n * @param {Object} [options]\n * @param {string} [options.cacheName] Cache name to store and retrieve\n * requests. Defaults to precache cache name provided by\n * [workbox-core.cacheNames]{@link workbox.core.cacheNames}.\n * @param {Array<RegExp>} [options.blacklist=[]] If any of these patterns\n * match, the route will not handle the request (even if a whitelist entry\n * matches).\n * @param {Array<RegExp>} [options.whitelist=[/./]] If any of these patterns\n * match the URL's pathname and search parameter, the route will handle the\n * request (assuming the blacklist doesn't match).\n * @return {workbox.routing.NavigationRoute} Returns the generated\n * Route.\n *\n * @alias workbox.routing.registerNavigationRoute\n */\n registerNavigationRoute(cachedAssetUrl, options = {}) {\n {\n assert_mjs.assert.isType(cachedAssetUrl, 'string', {\n moduleName: 'workbox-routing',\n className: '[default export]',\n funcName: 'registerNavigationRoute',\n paramName: 'cachedAssetUrl'\n });\n }\n\n const cacheName = cacheNames_mjs.cacheNames.getPrecacheName(options.cacheName);\n const handler = () => caches.match(cachedAssetUrl, { cacheName }).then(response => {\n if (response) {\n return response;\n }\n // This shouldn't normally happen, but there are edge cases:\n // https://github.com/GoogleChrome/workbox/issues/1441\n throw new Error(`The cache ${cacheName} did not have an entry for ` + `${cachedAssetUrl}.`);\n }).catch(error => {\n // If there's either a cache miss, or the caches.match() call threw\n // an exception, then attempt to fulfill the navigation request with\n // a response from the network rather than leaving the user with a\n // failed navigation.\n {\n logger_mjs.logger.debug(`Unable to respond to navigation request with cached ` + `response: ${error.message}. Falling back to network.`);\n }\n\n // This might still fail if the browser is offline...\n return fetch(cachedAssetUrl);\n });\n\n const route = new NavigationRoute(handler, {\n whitelist: options.whitelist,\n blacklist: options.blacklist\n });\n super.registerRoute(route);\n\n return route;\n }\n }\n\n const router = new DefaultRouter();\n\n // By default, register a fetch event listener that will respond to a request\n // only if there's a matching route.\n self.addEventListener('fetch', event => {\n const responsePromise = router.handleRequest(event);\n if (responsePromise) {\n event.respondWith(responsePromise);\n }\n });\n\n /*\n Copyright 2017 Google Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n const finalExport = Object.assign(router, publicAPI);\n\n return finalExport;\n\n}(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private));\n"],"file":"workbox-routing.dev.js"}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
this.workbox=this.workbox||{},this.workbox.routing=function(t,e){"use strict";try{self.workbox.v["workbox:routing:3.6.3"]=1}catch(t){}const r="GET";var s=t=>t&&"object"==typeof t?t:{handle:t};class n{constructor(t,e,n){this.handler=s(e),this.match=t,this.method=n||r}}class o extends n{constructor(t,e,r){super(({url:e})=>{const r=t.exec(e.href);return r?e.origin!==location.origin&&0!==r.index?null:r.slice(1):null},e,r)}}class i{constructor(){this.t=new Map}handleRequest(t){const e=new URL(t.request.url);if(!e.protocol.startsWith("http"))return;let r=null,s=null,n=null;const o=this.e(t,e);if(s=o.handler,n=o.params,r=o.route,!s&&this.r&&(s=this.r),!s)return;let i;try{i=s.handle({url:e,event:t,params:n})}catch(t){i=Promise.reject(t)}return i&&this.s&&(i=i.catch(r=>this.s.handle({url:e,event:t,err:r}))),i}e(t,e){const r=this.t.get(t.request.method)||[];for(const s of r){let r=s.match({url:e,event:t});if(r)return Array.isArray(r)&&0===r.length?r=void 0:(r.constructor===Object&&0===Object.keys(r).length||!0===r)&&(r=void 0),{route:s,params:r,handler:s.handler}}return{handler:void 0,params:void 0}}setDefaultHandler(t){this.r=s(t)}setCatchHandler(t){this.s=s(t)}registerRoute(t){this.t.has(t.method)||this.t.set(t.method,[]),this.t.get(t.method).push(t)}unregisterRoute(e){if(!this.t.has(e.method))throw new t.WorkboxError("unregister-route-but-not-found-with-method",{method:e.method});const r=this.t.get(e.method).indexOf(e);if(!(r>-1))throw new t.WorkboxError("unregister-route-route-not-registered");this.t.get(e.method).splice(r,1)}}class u extends n{constructor(t,{whitelist:e=[/./],blacklist:r=[]}={}){super((...t)=>this.n(...t),t),this.o=e,this.i=r}n({event:t,url:e}){if("navigate"!==t.request.mode)return!1;const r=e.pathname+e.search;return!this.i.some(t=>t.test(r))&&!!this.o.some(t=>t.test(r))}}var a=Object.freeze({RegExpRoute:o,Route:n,Router:i,NavigationRoute:u});const c=new class extends i{registerRoute(e,r,s="GET"){let i;if("string"==typeof e){const t=new URL(e,location);i=new n(({url:e})=>e.href===t.href,r,s)}else if(e instanceof RegExp)i=new o(e,r,s);else if("function"==typeof e)i=new n(e,r,s);else{if(!(e instanceof n))throw new t.WorkboxError("unsupported-route-type",{moduleName:"workbox-routing",className:"DefaultRouter",funcName:"registerRoute",paramName:"capture"});i=e}return super.registerRoute(i),i}registerNavigationRoute(t,r={}){const s=e.cacheNames.getPrecacheName(r.cacheName),n=new u(()=>caches.match(t,{cacheName:s}).then(e=>{if(e)return e;throw new Error(`The cache ${s} did not have an entry for `+`${t}.`)}).catch(e=>fetch(t)),{whitelist:r.whitelist,blacklist:r.blacklist});return super.registerRoute(n),n}};return self.addEventListener("fetch",t=>{const e=c.handleRequest(t);e&&t.respondWith(e)}),Object.assign(c,a)}(workbox.core._private,workbox.core._private);
|
2
|
+
|
3
|
+
//# sourceMappingURL=workbox-routing.prod.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"mappings":"","sources":["packages/workbox-routing/browser.mjs"],"sourcesContent":["this.workbox=this.workbox||{},this.workbox.routing=function(t,e){\"use strict\";try{self.workbox.v[\"workbox:routing:3.6.3\"]=1}catch(t){}const r=\"GET\";var s=t=>t&&\"object\"==typeof t?t:{handle:t};class n{constructor(t,e,n){this.handler=s(e),this.match=t,this.method=n||r}}class o extends n{constructor(t,e,r){super(({url:e})=>{const r=t.exec(e.href);return r?e.origin!==location.origin&&0!==r.index?null:r.slice(1):null},e,r)}}class i{constructor(){this.t=new Map}handleRequest(t){const e=new URL(t.request.url);if(!e.protocol.startsWith(\"http\"))return;let r=null,s=null,n=null;const o=this.e(t,e);if(s=o.handler,n=o.params,r=o.route,!s&&this.r&&(s=this.r),!s)return;let i;try{i=s.handle({url:e,event:t,params:n})}catch(t){i=Promise.reject(t)}return i&&this.s&&(i=i.catch(r=>this.s.handle({url:e,event:t,err:r}))),i}e(t,e){const r=this.t.get(t.request.method)||[];for(const s of r){let r=s.match({url:e,event:t});if(r)return Array.isArray(r)&&0===r.length?r=void 0:(r.constructor===Object&&0===Object.keys(r).length||!0===r)&&(r=void 0),{route:s,params:r,handler:s.handler}}return{handler:void 0,params:void 0}}setDefaultHandler(t){this.r=s(t)}setCatchHandler(t){this.s=s(t)}registerRoute(t){this.t.has(t.method)||this.t.set(t.method,[]),this.t.get(t.method).push(t)}unregisterRoute(e){if(!this.t.has(e.method))throw new t.WorkboxError(\"unregister-route-but-not-found-with-method\",{method:e.method});const r=this.t.get(e.method).indexOf(e);if(!(r>-1))throw new t.WorkboxError(\"unregister-route-route-not-registered\");this.t.get(e.method).splice(r,1)}}class u extends n{constructor(t,{whitelist:e=[/./],blacklist:r=[]}={}){super((...t)=>this.n(...t),t),this.o=e,this.i=r}n({event:t,url:e}){if(\"navigate\"!==t.request.mode)return!1;const r=e.pathname+e.search;return!this.i.some(t=>t.test(r))&&!!this.o.some(t=>t.test(r))}}var a=Object.freeze({RegExpRoute:o,Route:n,Router:i,NavigationRoute:u});const c=new class extends i{registerRoute(e,r,s=\"GET\"){let i;if(\"string\"==typeof e){const t=new URL(e,location);i=new n(({url:e})=>e.href===t.href,r,s)}else if(e instanceof RegExp)i=new o(e,r,s);else if(\"function\"==typeof e)i=new n(e,r,s);else{if(!(e instanceof n))throw new t.WorkboxError(\"unsupported-route-type\",{moduleName:\"workbox-routing\",className:\"DefaultRouter\",funcName:\"registerRoute\",paramName:\"capture\"});i=e}return super.registerRoute(i),i}registerNavigationRoute(t,r={}){const s=e.cacheNames.getPrecacheName(r.cacheName),n=new u(()=>caches.match(t,{cacheName:s}).then(e=>{if(e)return e;throw new Error(`The cache ${s} did not have an entry for `+`${t}.`)}).catch(e=>fetch(t)),{whitelist:r.whitelist,blacklist:r.blacklist});return super.registerRoute(n),n}};return self.addEventListener(\"fetch\",t=>{const e=c.handleRequest(t);e&&t.respondWith(e)}),Object.assign(c,a)}(workbox.core._private,workbox.core._private);\n"],"file":"workbox-routing.prod.js"}
|
@@ -0,0 +1,1172 @@
|
|
1
|
+
this.workbox = this.workbox || {};
|
2
|
+
this.workbox.strategies = (function (logger_mjs,assert_mjs,cacheNames_mjs,cacheWrapper_mjs,fetchWrapper_mjs,getFriendlyURL_mjs) {
|
3
|
+
'use strict';
|
4
|
+
|
5
|
+
try {
|
6
|
+
self.workbox.v['workbox:strategies:3.6.3'] = 1;
|
7
|
+
} catch (e) {} // eslint-disable-line
|
8
|
+
|
9
|
+
/*
|
10
|
+
Copyright 2018 Google Inc. All Rights Reserved.
|
11
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
12
|
+
you may not use this file except in compliance with the License.
|
13
|
+
You may obtain a copy of the License at
|
14
|
+
|
15
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
|
17
|
+
Unless required by applicable law or agreed to in writing, software
|
18
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
19
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
+
See the License for the specific language governing permissions and
|
21
|
+
limitations under the License.
|
22
|
+
*/
|
23
|
+
|
24
|
+
const getFriendlyURL = url => {
|
25
|
+
const urlObj = new URL(url, location);
|
26
|
+
if (urlObj.origin === location.origin) {
|
27
|
+
return urlObj.pathname;
|
28
|
+
}
|
29
|
+
return urlObj.href;
|
30
|
+
};
|
31
|
+
|
32
|
+
var messages = {
|
33
|
+
strategyStart: (strategyName, request) => `Using ${strategyName} to ` + `respond to '${getFriendlyURL(request.url)}'`,
|
34
|
+
printFinalResponse: response => {
|
35
|
+
if (response) {
|
36
|
+
logger_mjs.logger.groupCollapsed(`View the final response here.`);
|
37
|
+
logger_mjs.logger.unprefixed.log(response);
|
38
|
+
logger_mjs.logger.groupEnd();
|
39
|
+
}
|
40
|
+
}
|
41
|
+
};
|
42
|
+
|
43
|
+
/*
|
44
|
+
Copyright 2018 Google Inc. All Rights Reserved.
|
45
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
46
|
+
you may not use this file except in compliance with the License.
|
47
|
+
You may obtain a copy of the License at
|
48
|
+
|
49
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
50
|
+
|
51
|
+
Unless required by applicable law or agreed to in writing, software
|
52
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
53
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
54
|
+
See the License for the specific language governing permissions and
|
55
|
+
limitations under the License.
|
56
|
+
*/
|
57
|
+
|
58
|
+
/**
|
59
|
+
* An implementation of a [cache-first]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network}
|
60
|
+
* request strategy.
|
61
|
+
*
|
62
|
+
* A cache first strategy is useful for assets that have been revisioned,
|
63
|
+
* such as URLs like `/styles/example.a8f5f1.css`, since they
|
64
|
+
* can be cached for long periods of time.
|
65
|
+
*
|
66
|
+
* @memberof workbox.strategies
|
67
|
+
*/
|
68
|
+
class CacheFirst {
|
69
|
+
/**
|
70
|
+
* @param {Object} options
|
71
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
72
|
+
* requests. Defaults to cache names provided by
|
73
|
+
* [workbox-core]{@link workbox.core.cacheNames}.
|
74
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
75
|
+
* to use in conjunction with this caching strategy.
|
76
|
+
* @param {Object} options.fetchOptions Values passed along to the
|
77
|
+
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
78
|
+
* of all fetch() requests made by this strategy.
|
79
|
+
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
80
|
+
*/
|
81
|
+
constructor(options = {}) {
|
82
|
+
this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
|
83
|
+
this._plugins = options.plugins || [];
|
84
|
+
this._fetchOptions = options.fetchOptions || null;
|
85
|
+
this._matchOptions = options.matchOptions || null;
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* This method will perform a request strategy and follows an API that
|
90
|
+
* will work with the
|
91
|
+
* [Workbox Router]{@link workbox.routing.Router}.
|
92
|
+
*
|
93
|
+
* @param {Object} options
|
94
|
+
* @param {FetchEvent} options.event The fetch event to run this strategy
|
95
|
+
* against.
|
96
|
+
* @return {Promise<Response>}
|
97
|
+
*/
|
98
|
+
handle({ event }) {
|
99
|
+
var _this = this;
|
100
|
+
|
101
|
+
return babelHelpers.asyncToGenerator(function* () {
|
102
|
+
{
|
103
|
+
assert_mjs.assert.isInstance(event, FetchEvent, {
|
104
|
+
moduleName: 'workbox-strategies',
|
105
|
+
className: 'CacheFirst',
|
106
|
+
funcName: 'handle',
|
107
|
+
paramName: 'event'
|
108
|
+
});
|
109
|
+
}
|
110
|
+
|
111
|
+
return _this.makeRequest({
|
112
|
+
event,
|
113
|
+
request: event.request
|
114
|
+
});
|
115
|
+
})();
|
116
|
+
}
|
117
|
+
|
118
|
+
/**
|
119
|
+
* This method can be used to perform a make a standalone request outside the
|
120
|
+
* context of the [Workbox Router]{@link workbox.routing.Router}.
|
121
|
+
*
|
122
|
+
* See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
|
123
|
+
* for more usage information.
|
124
|
+
*
|
125
|
+
* @param {Object} options
|
126
|
+
* @param {Request|string} options.request Either a
|
127
|
+
* [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
|
128
|
+
* object, or a string URL, corresponding to the request to be made.
|
129
|
+
* @param {FetchEvent} [options.event] If provided, `event.waitUntil()` will
|
130
|
+
be called automatically to extend the service worker's lifetime.
|
131
|
+
* @return {Promise<Response>}
|
132
|
+
*/
|
133
|
+
makeRequest({ event, request }) {
|
134
|
+
var _this2 = this;
|
135
|
+
|
136
|
+
return babelHelpers.asyncToGenerator(function* () {
|
137
|
+
const logs = [];
|
138
|
+
|
139
|
+
if (typeof request === 'string') {
|
140
|
+
request = new Request(request);
|
141
|
+
}
|
142
|
+
|
143
|
+
{
|
144
|
+
assert_mjs.assert.isInstance(request, Request, {
|
145
|
+
moduleName: 'workbox-strategies',
|
146
|
+
className: 'CacheFirst',
|
147
|
+
funcName: 'makeRequest',
|
148
|
+
paramName: 'request'
|
149
|
+
});
|
150
|
+
}
|
151
|
+
|
152
|
+
let response = yield cacheWrapper_mjs.cacheWrapper.match({
|
153
|
+
cacheName: _this2._cacheName,
|
154
|
+
request,
|
155
|
+
event,
|
156
|
+
matchOptions: _this2._matchOptions,
|
157
|
+
plugins: _this2._plugins
|
158
|
+
});
|
159
|
+
|
160
|
+
let error;
|
161
|
+
if (!response) {
|
162
|
+
{
|
163
|
+
logs.push(`No response found in the '${_this2._cacheName}' cache. ` + `Will respond with a network request.`);
|
164
|
+
}
|
165
|
+
try {
|
166
|
+
response = yield _this2._getFromNetwork(request, event);
|
167
|
+
} catch (err) {
|
168
|
+
error = err;
|
169
|
+
}
|
170
|
+
|
171
|
+
{
|
172
|
+
if (response) {
|
173
|
+
logs.push(`Got response from network.`);
|
174
|
+
} else {
|
175
|
+
logs.push(`Unable to get a response from the network.`);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
} else {
|
179
|
+
{
|
180
|
+
logs.push(`Found a cached response in the '${_this2._cacheName}' cache.`);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
{
|
185
|
+
logger_mjs.logger.groupCollapsed(messages.strategyStart('CacheFirst', request));
|
186
|
+
for (let log of logs) {
|
187
|
+
logger_mjs.logger.log(log);
|
188
|
+
}
|
189
|
+
messages.printFinalResponse(response);
|
190
|
+
logger_mjs.logger.groupEnd();
|
191
|
+
}
|
192
|
+
|
193
|
+
if (error) {
|
194
|
+
// Don't swallow error as we'll want it to throw and enable catch
|
195
|
+
// handlers in router.
|
196
|
+
throw error;
|
197
|
+
}
|
198
|
+
|
199
|
+
return response;
|
200
|
+
})();
|
201
|
+
}
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Handles the network and cache part of CacheFirst.
|
205
|
+
*
|
206
|
+
* @param {Request} request
|
207
|
+
* @param {FetchEvent} [event]
|
208
|
+
* @return {Promise<Response>}
|
209
|
+
*
|
210
|
+
* @private
|
211
|
+
*/
|
212
|
+
_getFromNetwork(request, event) {
|
213
|
+
var _this3 = this;
|
214
|
+
|
215
|
+
return babelHelpers.asyncToGenerator(function* () {
|
216
|
+
const response = yield fetchWrapper_mjs.fetchWrapper.fetch({
|
217
|
+
request,
|
218
|
+
event,
|
219
|
+
fetchOptions: _this3._fetchOptions,
|
220
|
+
plugins: _this3._plugins
|
221
|
+
});
|
222
|
+
|
223
|
+
// Keep the service worker while we put the request to the cache
|
224
|
+
const responseClone = response.clone();
|
225
|
+
const cachePutPromise = cacheWrapper_mjs.cacheWrapper.put({
|
226
|
+
cacheName: _this3._cacheName,
|
227
|
+
request,
|
228
|
+
response: responseClone,
|
229
|
+
event,
|
230
|
+
plugins: _this3._plugins
|
231
|
+
});
|
232
|
+
|
233
|
+
if (event) {
|
234
|
+
try {
|
235
|
+
event.waitUntil(cachePutPromise);
|
236
|
+
} catch (error) {
|
237
|
+
{
|
238
|
+
logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
return response;
|
244
|
+
})();
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
/*
|
249
|
+
Copyright 2018 Google Inc. All Rights Reserved.
|
250
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
251
|
+
you may not use this file except in compliance with the License.
|
252
|
+
You may obtain a copy of the License at
|
253
|
+
|
254
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
255
|
+
|
256
|
+
Unless required by applicable law or agreed to in writing, software
|
257
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
258
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
259
|
+
See the License for the specific language governing permissions and
|
260
|
+
limitations under the License.
|
261
|
+
*/
|
262
|
+
|
263
|
+
/**
|
264
|
+
* An implementation of a
|
265
|
+
* [cache-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-only}
|
266
|
+
* request strategy.
|
267
|
+
*
|
268
|
+
* This class is useful if you want to take advantage of any [Workbox plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}.
|
269
|
+
*
|
270
|
+
* @memberof workbox.strategies
|
271
|
+
*/
|
272
|
+
class CacheOnly {
|
273
|
+
/**
|
274
|
+
* @param {Object} options
|
275
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
276
|
+
* requests. Defaults to cache names provided by
|
277
|
+
* [workbox-core]{@link workbox.core.cacheNames}.
|
278
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
279
|
+
* to use in conjunction with this caching strategy.
|
280
|
+
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
281
|
+
*/
|
282
|
+
constructor(options = {}) {
|
283
|
+
this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
|
284
|
+
this._plugins = options.plugins || [];
|
285
|
+
this._matchOptions = options.matchOptions || null;
|
286
|
+
}
|
287
|
+
|
288
|
+
/**
|
289
|
+
* This method will perform a request strategy and follows an API that
|
290
|
+
* will work with the
|
291
|
+
* [Workbox Router]{@link workbox.routing.Router}.
|
292
|
+
*
|
293
|
+
* @param {Object} options
|
294
|
+
* @param {FetchEvent} options.event The fetch event to run this strategy
|
295
|
+
* against.
|
296
|
+
* @return {Promise<Response>}
|
297
|
+
*/
|
298
|
+
handle({ event }) {
|
299
|
+
var _this = this;
|
300
|
+
|
301
|
+
return babelHelpers.asyncToGenerator(function* () {
|
302
|
+
{
|
303
|
+
assert_mjs.assert.isInstance(event, FetchEvent, {
|
304
|
+
moduleName: 'workbox-strategies',
|
305
|
+
className: 'CacheOnly',
|
306
|
+
funcName: 'handle',
|
307
|
+
paramName: 'event'
|
308
|
+
});
|
309
|
+
}
|
310
|
+
|
311
|
+
return _this.makeRequest({
|
312
|
+
event,
|
313
|
+
request: event.request
|
314
|
+
});
|
315
|
+
})();
|
316
|
+
}
|
317
|
+
|
318
|
+
/**
|
319
|
+
* This method can be used to perform a make a standalone request outside the
|
320
|
+
* context of the [Workbox Router]{@link workbox.routing.Router}.
|
321
|
+
*
|
322
|
+
* See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
|
323
|
+
* for more usage information.
|
324
|
+
*
|
325
|
+
* @param {Object} options
|
326
|
+
* @param {Request|string} options.request Either a
|
327
|
+
* [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
|
328
|
+
* object, or a string URL, corresponding to the request to be made.
|
329
|
+
* @param {FetchEvent} [options.event] If provided, `event.waitUntil()` will
|
330
|
+
* be called automatically to extend the service worker's lifetime.
|
331
|
+
* @return {Promise<Response>}
|
332
|
+
*/
|
333
|
+
makeRequest({ event, request }) {
|
334
|
+
var _this2 = this;
|
335
|
+
|
336
|
+
return babelHelpers.asyncToGenerator(function* () {
|
337
|
+
if (typeof request === 'string') {
|
338
|
+
request = new Request(request);
|
339
|
+
}
|
340
|
+
|
341
|
+
{
|
342
|
+
assert_mjs.assert.isInstance(request, Request, {
|
343
|
+
moduleName: 'workbox-strategies',
|
344
|
+
className: 'CacheOnly',
|
345
|
+
funcName: 'makeRequest',
|
346
|
+
paramName: 'request'
|
347
|
+
});
|
348
|
+
}
|
349
|
+
|
350
|
+
const response = yield cacheWrapper_mjs.cacheWrapper.match({
|
351
|
+
cacheName: _this2._cacheName,
|
352
|
+
request,
|
353
|
+
event,
|
354
|
+
matchOptions: _this2._matchOptions,
|
355
|
+
plugins: _this2._plugins
|
356
|
+
});
|
357
|
+
|
358
|
+
{
|
359
|
+
logger_mjs.logger.groupCollapsed(messages.strategyStart('CacheOnly', request));
|
360
|
+
if (response) {
|
361
|
+
logger_mjs.logger.log(`Found a cached response in the '${_this2._cacheName}'` + ` cache.`);
|
362
|
+
messages.printFinalResponse(response);
|
363
|
+
} else {
|
364
|
+
logger_mjs.logger.log(`No response found in the '${_this2._cacheName}' cache.`);
|
365
|
+
}
|
366
|
+
logger_mjs.logger.groupEnd();
|
367
|
+
}
|
368
|
+
|
369
|
+
return response;
|
370
|
+
})();
|
371
|
+
}
|
372
|
+
}
|
373
|
+
|
374
|
+
/*
|
375
|
+
Copyright 2016 Google Inc. All Rights Reserved.
|
376
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
377
|
+
you may not use this file except in compliance with the License.
|
378
|
+
You may obtain a copy of the License at
|
379
|
+
|
380
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
381
|
+
|
382
|
+
Unless required by applicable law or agreed to in writing, software
|
383
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
384
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
385
|
+
See the License for the specific language governing permissions and
|
386
|
+
limitations under the License.
|
387
|
+
*/
|
388
|
+
|
389
|
+
var cacheOkAndOpaquePlugin = {
|
390
|
+
/**
|
391
|
+
* Return return a response (i.e. allow caching) if the
|
392
|
+
* response is ok (i.e. 200) or is opaque.
|
393
|
+
*
|
394
|
+
* @param {Object} options
|
395
|
+
* @param {Response} options.response
|
396
|
+
* @return {Response|null}
|
397
|
+
*
|
398
|
+
* @private
|
399
|
+
*/
|
400
|
+
cacheWillUpdate: ({ response }) => {
|
401
|
+
if (response.ok || response.status === 0) {
|
402
|
+
return response;
|
403
|
+
}
|
404
|
+
return null;
|
405
|
+
}
|
406
|
+
};
|
407
|
+
|
408
|
+
/*
|
409
|
+
Copyright 2018 Google Inc. All Rights Reserved.
|
410
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
411
|
+
you may not use this file except in compliance with the License.
|
412
|
+
You may obtain a copy of the License at
|
413
|
+
|
414
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
415
|
+
|
416
|
+
Unless required by applicable law or agreed to in writing, software
|
417
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
418
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
419
|
+
See the License for the specific language governing permissions and
|
420
|
+
limitations under the License.
|
421
|
+
*/
|
422
|
+
|
423
|
+
/**
|
424
|
+
* An implementation of a
|
425
|
+
* [network first]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-falling-back-to-cache}
|
426
|
+
* request strategy.
|
427
|
+
*
|
428
|
+
* By default, this strategy will cache responses with a 200 status code as
|
429
|
+
* well as [opaque responses]{@link https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests}.
|
430
|
+
* Opaque responses are are cross-origin requests where the response doesn't
|
431
|
+
* support [CORS]{@link https://enable-cors.org/}.
|
432
|
+
*
|
433
|
+
* @memberof workbox.strategies
|
434
|
+
*/
|
435
|
+
class NetworkFirst {
|
436
|
+
/**
|
437
|
+
* @param {Object} options
|
438
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
439
|
+
* requests. Defaults to cache names provided by
|
440
|
+
* [workbox-core]{@link workbox.core.cacheNames}.
|
441
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
442
|
+
* to use in conjunction with this caching strategy.
|
443
|
+
* @param {Object} options.fetchOptions Values passed along to the
|
444
|
+
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
445
|
+
* of all fetch() requests made by this strategy.
|
446
|
+
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
447
|
+
* @param {number} options.networkTimeoutSeconds If set, any network requests
|
448
|
+
* that fail to respond within the timeout will fallback to the cache.
|
449
|
+
*
|
450
|
+
* This option can be used to combat
|
451
|
+
* "[lie-fi]{@link https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi}"
|
452
|
+
* scenarios.
|
453
|
+
*/
|
454
|
+
constructor(options = {}) {
|
455
|
+
this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
|
456
|
+
|
457
|
+
if (options.plugins) {
|
458
|
+
let isUsingCacheWillUpdate = options.plugins.some(plugin => !!plugin.cacheWillUpdate);
|
459
|
+
this._plugins = isUsingCacheWillUpdate ? options.plugins : [cacheOkAndOpaquePlugin, ...options.plugins];
|
460
|
+
} else {
|
461
|
+
// No plugins passed in, use the default plugin.
|
462
|
+
this._plugins = [cacheOkAndOpaquePlugin];
|
463
|
+
}
|
464
|
+
|
465
|
+
this._networkTimeoutSeconds = options.networkTimeoutSeconds;
|
466
|
+
{
|
467
|
+
if (this._networkTimeoutSeconds) {
|
468
|
+
assert_mjs.assert.isType(this._networkTimeoutSeconds, 'number', {
|
469
|
+
moduleName: 'workbox-strategies',
|
470
|
+
className: 'NetworkFirst',
|
471
|
+
funcName: 'constructor',
|
472
|
+
paramName: 'networkTimeoutSeconds'
|
473
|
+
});
|
474
|
+
}
|
475
|
+
}
|
476
|
+
|
477
|
+
this._fetchOptions = options.fetchOptions || null;
|
478
|
+
this._matchOptions = options.matchOptions || null;
|
479
|
+
}
|
480
|
+
|
481
|
+
/**
|
482
|
+
* This method will perform a request strategy and follows an API that
|
483
|
+
* will work with the
|
484
|
+
* [Workbox Router]{@link workbox.routing.Router}.
|
485
|
+
*
|
486
|
+
* @param {Object} options
|
487
|
+
* @param {FetchEvent} options.event The fetch event to run this strategy
|
488
|
+
* against.
|
489
|
+
* @return {Promise<Response>}
|
490
|
+
*/
|
491
|
+
handle({ event }) {
|
492
|
+
var _this = this;
|
493
|
+
|
494
|
+
return babelHelpers.asyncToGenerator(function* () {
|
495
|
+
{
|
496
|
+
assert_mjs.assert.isInstance(event, FetchEvent, {
|
497
|
+
moduleName: 'workbox-strategies',
|
498
|
+
className: 'NetworkFirst',
|
499
|
+
funcName: 'handle',
|
500
|
+
paramName: 'event'
|
501
|
+
});
|
502
|
+
}
|
503
|
+
|
504
|
+
return _this.makeRequest({
|
505
|
+
event,
|
506
|
+
request: event.request
|
507
|
+
});
|
508
|
+
})();
|
509
|
+
}
|
510
|
+
|
511
|
+
/**
|
512
|
+
* This method can be used to perform a make a standalone request outside the
|
513
|
+
* context of the [Workbox Router]{@link workbox.routing.Router}.
|
514
|
+
*
|
515
|
+
* See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
|
516
|
+
* for more usage information.
|
517
|
+
*
|
518
|
+
* @param {Object} options
|
519
|
+
* @param {Request|string} options.request Either a
|
520
|
+
* [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
|
521
|
+
* object, or a string URL, corresponding to the request to be made.
|
522
|
+
* @param {FetchEvent} [options.event] If provided, `event.waitUntil()` will
|
523
|
+
* be called automatically to extend the service worker's lifetime.
|
524
|
+
* @return {Promise<Response>}
|
525
|
+
*/
|
526
|
+
makeRequest({ event, request }) {
|
527
|
+
var _this2 = this;
|
528
|
+
|
529
|
+
return babelHelpers.asyncToGenerator(function* () {
|
530
|
+
const logs = [];
|
531
|
+
|
532
|
+
if (typeof request === 'string') {
|
533
|
+
request = new Request(request);
|
534
|
+
}
|
535
|
+
|
536
|
+
{
|
537
|
+
assert_mjs.assert.isInstance(request, Request, {
|
538
|
+
moduleName: 'workbox-strategies',
|
539
|
+
className: 'NetworkFirst',
|
540
|
+
funcName: 'handle',
|
541
|
+
paramName: 'makeRequest'
|
542
|
+
});
|
543
|
+
}
|
544
|
+
|
545
|
+
const promises = [];
|
546
|
+
let timeoutId;
|
547
|
+
|
548
|
+
if (_this2._networkTimeoutSeconds) {
|
549
|
+
const { id, promise } = _this2._getTimeoutPromise({ request, event, logs });
|
550
|
+
timeoutId = id;
|
551
|
+
promises.push(promise);
|
552
|
+
}
|
553
|
+
|
554
|
+
const networkPromise = _this2._getNetworkPromise({ timeoutId, request, event, logs });
|
555
|
+
promises.push(networkPromise);
|
556
|
+
|
557
|
+
// Promise.race() will resolve as soon as the first promise resolves.
|
558
|
+
let response = yield Promise.race(promises);
|
559
|
+
// If Promise.race() resolved with null, it might be due to a network
|
560
|
+
// timeout + a cache miss. If that were to happen, we'd rather wait until
|
561
|
+
// the networkPromise resolves instead of returning null.
|
562
|
+
// Note that it's fine to await an already-resolved promise, so we don't
|
563
|
+
// have to check to see if it's still "in flight".
|
564
|
+
if (!response) {
|
565
|
+
response = yield networkPromise;
|
566
|
+
}
|
567
|
+
|
568
|
+
{
|
569
|
+
logger_mjs.logger.groupCollapsed(messages.strategyStart('NetworkFirst', request));
|
570
|
+
for (let log of logs) {
|
571
|
+
logger_mjs.logger.log(log);
|
572
|
+
}
|
573
|
+
messages.printFinalResponse(response);
|
574
|
+
logger_mjs.logger.groupEnd();
|
575
|
+
}
|
576
|
+
|
577
|
+
return response;
|
578
|
+
})();
|
579
|
+
}
|
580
|
+
|
581
|
+
/**
|
582
|
+
* @param {Object} options
|
583
|
+
* @param {Request} options.request
|
584
|
+
* @param {Array} options.logs A reference to the logs array
|
585
|
+
* @param {Event} [options.event]
|
586
|
+
* @return {Promise<Response>}
|
587
|
+
*
|
588
|
+
* @private
|
589
|
+
*/
|
590
|
+
_getTimeoutPromise({ request, logs, event }) {
|
591
|
+
var _this3 = this;
|
592
|
+
|
593
|
+
let timeoutId;
|
594
|
+
const timeoutPromise = new Promise(resolve => {
|
595
|
+
const onNetworkTimeout = (() => {
|
596
|
+
var _ref = babelHelpers.asyncToGenerator(function* () {
|
597
|
+
{
|
598
|
+
logs.push(`Timing out the network response at ` + `${_this3._networkTimeoutSeconds} seconds.`);
|
599
|
+
}
|
600
|
+
|
601
|
+
resolve((yield _this3._respondFromCache({ request, event })));
|
602
|
+
});
|
603
|
+
|
604
|
+
return function onNetworkTimeout() {
|
605
|
+
return _ref.apply(this, arguments);
|
606
|
+
};
|
607
|
+
})();
|
608
|
+
|
609
|
+
timeoutId = setTimeout(onNetworkTimeout, this._networkTimeoutSeconds * 1000);
|
610
|
+
});
|
611
|
+
|
612
|
+
return {
|
613
|
+
promise: timeoutPromise,
|
614
|
+
id: timeoutId
|
615
|
+
};
|
616
|
+
}
|
617
|
+
|
618
|
+
/**
|
619
|
+
* @param {Object} options
|
620
|
+
* @param {number|undefined} options.timeoutId
|
621
|
+
* @param {Request} options.request
|
622
|
+
* @param {Array} options.logs A reference to the logs Array.
|
623
|
+
* @param {Event} [options.event]
|
624
|
+
* @return {Promise<Response>}
|
625
|
+
*
|
626
|
+
* @private
|
627
|
+
*/
|
628
|
+
_getNetworkPromise({ timeoutId, request, logs, event }) {
|
629
|
+
var _this4 = this;
|
630
|
+
|
631
|
+
return babelHelpers.asyncToGenerator(function* () {
|
632
|
+
let error;
|
633
|
+
let response;
|
634
|
+
try {
|
635
|
+
response = yield fetchWrapper_mjs.fetchWrapper.fetch({
|
636
|
+
request,
|
637
|
+
event,
|
638
|
+
fetchOptions: _this4._fetchOptions,
|
639
|
+
plugins: _this4._plugins
|
640
|
+
});
|
641
|
+
} catch (err) {
|
642
|
+
error = err;
|
643
|
+
}
|
644
|
+
|
645
|
+
if (timeoutId) {
|
646
|
+
clearTimeout(timeoutId);
|
647
|
+
}
|
648
|
+
|
649
|
+
{
|
650
|
+
if (response) {
|
651
|
+
logs.push(`Got response from network.`);
|
652
|
+
} else {
|
653
|
+
logs.push(`Unable to get a response from the network. Will respond ` + `with a cached response.`);
|
654
|
+
}
|
655
|
+
}
|
656
|
+
|
657
|
+
if (error || !response) {
|
658
|
+
response = yield _this4._respondFromCache({ request, event });
|
659
|
+
{
|
660
|
+
if (response) {
|
661
|
+
logs.push(`Found a cached response in the '${_this4._cacheName}'` + ` cache.`);
|
662
|
+
} else {
|
663
|
+
logs.push(`No response found in the '${_this4._cacheName}' cache.`);
|
664
|
+
}
|
665
|
+
}
|
666
|
+
} else {
|
667
|
+
// Keep the service worker alive while we put the request in the cache
|
668
|
+
const responseClone = response.clone();
|
669
|
+
const cachePut = cacheWrapper_mjs.cacheWrapper.put({
|
670
|
+
cacheName: _this4._cacheName,
|
671
|
+
request,
|
672
|
+
response: responseClone,
|
673
|
+
event,
|
674
|
+
plugins: _this4._plugins
|
675
|
+
});
|
676
|
+
|
677
|
+
if (event) {
|
678
|
+
try {
|
679
|
+
// The event has been responded to so we can keep the SW alive to
|
680
|
+
// respond to the request
|
681
|
+
event.waitUntil(cachePut);
|
682
|
+
} catch (err) {
|
683
|
+
{
|
684
|
+
logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
|
685
|
+
}
|
686
|
+
}
|
687
|
+
}
|
688
|
+
}
|
689
|
+
|
690
|
+
return response;
|
691
|
+
})();
|
692
|
+
}
|
693
|
+
|
694
|
+
/**
|
695
|
+
* Used if the network timeouts or fails to make the request.
|
696
|
+
*
|
697
|
+
* @param {Object} options
|
698
|
+
* @param {Request} request The request to match in the cache
|
699
|
+
* @param {Event} [options.event]
|
700
|
+
* @return {Promise<Object>}
|
701
|
+
*
|
702
|
+
* @private
|
703
|
+
*/
|
704
|
+
_respondFromCache({ event, request }) {
|
705
|
+
return cacheWrapper_mjs.cacheWrapper.match({
|
706
|
+
cacheName: this._cacheName,
|
707
|
+
request,
|
708
|
+
event,
|
709
|
+
matchOptions: this._matchOptions,
|
710
|
+
plugins: this._plugins
|
711
|
+
});
|
712
|
+
}
|
713
|
+
}
|
714
|
+
|
715
|
+
/*
|
716
|
+
Copyright 2018 Google Inc. All Rights Reserved.
|
717
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
718
|
+
you may not use this file except in compliance with the License.
|
719
|
+
You may obtain a copy of the License at
|
720
|
+
|
721
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
722
|
+
|
723
|
+
Unless required by applicable law or agreed to in writing, software
|
724
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
725
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
726
|
+
See the License for the specific language governing permissions and
|
727
|
+
limitations under the License.
|
728
|
+
*/
|
729
|
+
|
730
|
+
/**
|
731
|
+
* An implementation of a
|
732
|
+
* [network-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-only}
|
733
|
+
* request strategy.
|
734
|
+
*
|
735
|
+
* This class is useful if you want to take advantage of any [Workbox plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}.
|
736
|
+
*
|
737
|
+
* @memberof workbox.strategies
|
738
|
+
*/
|
739
|
+
class NetworkOnly {
|
740
|
+
/**
|
741
|
+
* @param {Object} options
|
742
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
743
|
+
* requests. Defaults to cache names provided by
|
744
|
+
* [workbox-core]{@link workbox.core.cacheNames}.
|
745
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
746
|
+
* to use in conjunction with this caching strategy.
|
747
|
+
* @param {Object} options.fetchOptions Values passed along to the
|
748
|
+
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
749
|
+
* of all fetch() requests made by this strategy.
|
750
|
+
*/
|
751
|
+
constructor(options = {}) {
|
752
|
+
this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
|
753
|
+
this._plugins = options.plugins || [];
|
754
|
+
this._fetchOptions = options.fetchOptions || null;
|
755
|
+
}
|
756
|
+
|
757
|
+
/**
|
758
|
+
* This method will perform a request strategy and follows an API that
|
759
|
+
* will work with the
|
760
|
+
* [Workbox Router]{@link workbox.routing.Router}.
|
761
|
+
*
|
762
|
+
* @param {Object} options
|
763
|
+
* @param {FetchEvent} options.event The fetch event to run this strategy
|
764
|
+
* against.
|
765
|
+
* @return {Promise<Response>}
|
766
|
+
*/
|
767
|
+
handle({ event }) {
|
768
|
+
var _this = this;
|
769
|
+
|
770
|
+
return babelHelpers.asyncToGenerator(function* () {
|
771
|
+
{
|
772
|
+
assert_mjs.assert.isInstance(event, FetchEvent, {
|
773
|
+
moduleName: 'workbox-strategies',
|
774
|
+
className: 'NetworkOnly',
|
775
|
+
funcName: 'handle',
|
776
|
+
paramName: 'event'
|
777
|
+
});
|
778
|
+
}
|
779
|
+
|
780
|
+
return _this.makeRequest({
|
781
|
+
event,
|
782
|
+
request: event.request
|
783
|
+
});
|
784
|
+
})();
|
785
|
+
}
|
786
|
+
|
787
|
+
/**
|
788
|
+
* This method can be used to perform a make a standalone request outside the
|
789
|
+
* context of the [Workbox Router]{@link workbox.routing.Router}.
|
790
|
+
*
|
791
|
+
* See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
|
792
|
+
* for more usage information.
|
793
|
+
*
|
794
|
+
* @param {Object} options
|
795
|
+
* @param {Request|string} options.request Either a
|
796
|
+
* [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
|
797
|
+
* object, or a string URL, corresponding to the request to be made.
|
798
|
+
* @param {FetchEvent} [options.event] If provided, `event.waitUntil()` will
|
799
|
+
* be called automatically to extend the service worker's lifetime.
|
800
|
+
* @return {Promise<Response>}
|
801
|
+
*/
|
802
|
+
makeRequest({ event, request }) {
|
803
|
+
var _this2 = this;
|
804
|
+
|
805
|
+
return babelHelpers.asyncToGenerator(function* () {
|
806
|
+
if (typeof request === 'string') {
|
807
|
+
request = new Request(request);
|
808
|
+
}
|
809
|
+
|
810
|
+
{
|
811
|
+
assert_mjs.assert.isInstance(request, Request, {
|
812
|
+
moduleName: 'workbox-strategies',
|
813
|
+
className: 'NetworkOnly',
|
814
|
+
funcName: 'handle',
|
815
|
+
paramName: 'request'
|
816
|
+
});
|
817
|
+
}
|
818
|
+
|
819
|
+
let error;
|
820
|
+
let response;
|
821
|
+
try {
|
822
|
+
response = yield fetchWrapper_mjs.fetchWrapper.fetch({
|
823
|
+
request,
|
824
|
+
event,
|
825
|
+
fetchOptions: _this2._fetchOptions,
|
826
|
+
plugins: _this2._plugins
|
827
|
+
});
|
828
|
+
} catch (err) {
|
829
|
+
error = err;
|
830
|
+
}
|
831
|
+
|
832
|
+
{
|
833
|
+
logger_mjs.logger.groupCollapsed(messages.strategyStart('NetworkOnly', request));
|
834
|
+
if (response) {
|
835
|
+
logger_mjs.logger.log(`Got response from network.`);
|
836
|
+
} else {
|
837
|
+
logger_mjs.logger.log(`Unable to get a response from the network.`);
|
838
|
+
}
|
839
|
+
messages.printFinalResponse(response);
|
840
|
+
logger_mjs.logger.groupEnd();
|
841
|
+
}
|
842
|
+
|
843
|
+
// If there was an error thrown, re-throw it to ensure the Routers
|
844
|
+
// catch handler is triggered.
|
845
|
+
if (error) {
|
846
|
+
throw error;
|
847
|
+
}
|
848
|
+
|
849
|
+
return response;
|
850
|
+
})();
|
851
|
+
}
|
852
|
+
}
|
853
|
+
|
854
|
+
/*
|
855
|
+
Copyright 2018 Google Inc. All Rights Reserved.
|
856
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
857
|
+
you may not use this file except in compliance with the License.
|
858
|
+
You may obtain a copy of the License at
|
859
|
+
|
860
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
861
|
+
|
862
|
+
Unless required by applicable law or agreed to in writing, software
|
863
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
864
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
865
|
+
See the License for the specific language governing permissions and
|
866
|
+
limitations under the License.
|
867
|
+
*/
|
868
|
+
|
869
|
+
/**
|
870
|
+
* An implementation of a
|
871
|
+
* [stale-while-revalidate]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#stale-while-revalidate}
|
872
|
+
* request strategy.
|
873
|
+
*
|
874
|
+
* Resources are requested from both the cache and the network in parallel.
|
875
|
+
* The strategy will respond with the cached version if available, otherwise
|
876
|
+
* wait for the network response. The cache is updated with the network response
|
877
|
+
* with each successful request.
|
878
|
+
*
|
879
|
+
* By default, this strategy will cache responses with a 200 status code as
|
880
|
+
* well as [opaque responses]{@link https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests}.
|
881
|
+
* Opaque responses are are cross-origin requests where the response doesn't
|
882
|
+
* support [CORS]{@link https://enable-cors.org/}.
|
883
|
+
*
|
884
|
+
* @memberof workbox.strategies
|
885
|
+
*/
|
886
|
+
class StaleWhileRevalidate {
|
887
|
+
/**
|
888
|
+
* @param {Object} options
|
889
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
890
|
+
* requests. Defaults to cache names provided by
|
891
|
+
* [workbox-core]{@link workbox.core.cacheNames}.
|
892
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
893
|
+
* to use in conjunction with this caching strategy.
|
894
|
+
* @param {Object} options.fetchOptions Values passed along to the
|
895
|
+
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
896
|
+
* of all fetch() requests made by this strategy.
|
897
|
+
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
898
|
+
*/
|
899
|
+
constructor(options = {}) {
|
900
|
+
this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
|
901
|
+
this._plugins = options.plugins || [];
|
902
|
+
|
903
|
+
if (options.plugins) {
|
904
|
+
let isUsingCacheWillUpdate = options.plugins.some(plugin => !!plugin.cacheWillUpdate);
|
905
|
+
this._plugins = isUsingCacheWillUpdate ? options.plugins : [cacheOkAndOpaquePlugin, ...options.plugins];
|
906
|
+
} else {
|
907
|
+
// No plugins passed in, use the default plugin.
|
908
|
+
this._plugins = [cacheOkAndOpaquePlugin];
|
909
|
+
}
|
910
|
+
|
911
|
+
this._fetchOptions = options.fetchOptions || null;
|
912
|
+
this._matchOptions = options.matchOptions || null;
|
913
|
+
}
|
914
|
+
|
915
|
+
/**
|
916
|
+
* This method will perform a request strategy and follows an API that
|
917
|
+
* will work with the
|
918
|
+
* [Workbox Router]{@link workbox.routing.Router}.
|
919
|
+
*
|
920
|
+
* @param {Object} options
|
921
|
+
* @param {FetchEvent} options.event The fetch event to run this strategy
|
922
|
+
* against.
|
923
|
+
* @return {Promise<Response>}
|
924
|
+
*/
|
925
|
+
handle({ event }) {
|
926
|
+
var _this = this;
|
927
|
+
|
928
|
+
return babelHelpers.asyncToGenerator(function* () {
|
929
|
+
{
|
930
|
+
assert_mjs.assert.isInstance(event, FetchEvent, {
|
931
|
+
moduleName: 'workbox-strategies',
|
932
|
+
className: 'StaleWhileRevalidate',
|
933
|
+
funcName: 'handle',
|
934
|
+
paramName: 'event'
|
935
|
+
});
|
936
|
+
}
|
937
|
+
|
938
|
+
return _this.makeRequest({
|
939
|
+
event,
|
940
|
+
request: event.request
|
941
|
+
});
|
942
|
+
})();
|
943
|
+
}
|
944
|
+
|
945
|
+
/**
|
946
|
+
* This method can be used to perform a make a standalone request outside the
|
947
|
+
* context of the [Workbox Router]{@link workbox.routing.Router}.
|
948
|
+
*
|
949
|
+
* See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
|
950
|
+
* for more usage information.
|
951
|
+
*
|
952
|
+
* @param {Object} options
|
953
|
+
* @param {Request|string} options.request Either a
|
954
|
+
* [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
|
955
|
+
* object, or a string URL, corresponding to the request to be made.
|
956
|
+
* @param {FetchEvent} [options.event] If provided, `event.waitUntil()` will
|
957
|
+
* be called automatically to extend the service worker's lifetime.
|
958
|
+
* @return {Promise<Response>}
|
959
|
+
*/
|
960
|
+
makeRequest({ event, request }) {
|
961
|
+
var _this2 = this;
|
962
|
+
|
963
|
+
return babelHelpers.asyncToGenerator(function* () {
|
964
|
+
const logs = [];
|
965
|
+
|
966
|
+
if (typeof request === 'string') {
|
967
|
+
request = new Request(request);
|
968
|
+
}
|
969
|
+
|
970
|
+
{
|
971
|
+
assert_mjs.assert.isInstance(request, Request, {
|
972
|
+
moduleName: 'workbox-strategies',
|
973
|
+
className: 'StaleWhileRevalidate',
|
974
|
+
funcName: 'handle',
|
975
|
+
paramName: 'request'
|
976
|
+
});
|
977
|
+
}
|
978
|
+
|
979
|
+
const fetchAndCachePromise = _this2._getFromNetwork({ request, event });
|
980
|
+
|
981
|
+
let response = yield cacheWrapper_mjs.cacheWrapper.match({
|
982
|
+
cacheName: _this2._cacheName,
|
983
|
+
request,
|
984
|
+
event,
|
985
|
+
matchOptions: _this2._matchOptions,
|
986
|
+
plugins: _this2._plugins
|
987
|
+
});
|
988
|
+
|
989
|
+
if (response) {
|
990
|
+
{
|
991
|
+
logs.push(`Found a cached response in the '${_this2._cacheName}'` + ` cache. Will update with the network response in the background.`);
|
992
|
+
}
|
993
|
+
|
994
|
+
if (event) {
|
995
|
+
try {
|
996
|
+
event.waitUntil(fetchAndCachePromise);
|
997
|
+
} catch (error) {
|
998
|
+
{
|
999
|
+
logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
|
1000
|
+
}
|
1001
|
+
}
|
1002
|
+
}
|
1003
|
+
} else {
|
1004
|
+
{
|
1005
|
+
logs.push(`No response found in the '${_this2._cacheName}' cache. ` + `Will wait for the network response.`);
|
1006
|
+
}
|
1007
|
+
response = yield fetchAndCachePromise;
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
{
|
1011
|
+
logger_mjs.logger.groupCollapsed(messages.strategyStart('StaleWhileRevalidate', request));
|
1012
|
+
for (let log of logs) {
|
1013
|
+
logger_mjs.logger.log(log);
|
1014
|
+
}
|
1015
|
+
messages.printFinalResponse(response);
|
1016
|
+
logger_mjs.logger.groupEnd();
|
1017
|
+
}
|
1018
|
+
|
1019
|
+
return response;
|
1020
|
+
})();
|
1021
|
+
}
|
1022
|
+
|
1023
|
+
/**
|
1024
|
+
* @param {Object} options
|
1025
|
+
* @param {Request} options.request
|
1026
|
+
* @param {Event} [options.event]
|
1027
|
+
* @return {Promise<Response>}
|
1028
|
+
*
|
1029
|
+
* @private
|
1030
|
+
*/
|
1031
|
+
_getFromNetwork({ request, event }) {
|
1032
|
+
var _this3 = this;
|
1033
|
+
|
1034
|
+
return babelHelpers.asyncToGenerator(function* () {
|
1035
|
+
const response = yield fetchWrapper_mjs.fetchWrapper.fetch({
|
1036
|
+
request,
|
1037
|
+
event,
|
1038
|
+
fetchOptions: _this3._fetchOptions,
|
1039
|
+
plugins: _this3._plugins
|
1040
|
+
});
|
1041
|
+
|
1042
|
+
const cachePutPromise = cacheWrapper_mjs.cacheWrapper.put({
|
1043
|
+
cacheName: _this3._cacheName,
|
1044
|
+
request,
|
1045
|
+
response: response.clone(),
|
1046
|
+
event,
|
1047
|
+
plugins: _this3._plugins
|
1048
|
+
});
|
1049
|
+
|
1050
|
+
if (event) {
|
1051
|
+
try {
|
1052
|
+
event.waitUntil(cachePutPromise);
|
1053
|
+
} catch (error) {
|
1054
|
+
{
|
1055
|
+
logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
|
1056
|
+
}
|
1057
|
+
}
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
return response;
|
1061
|
+
})();
|
1062
|
+
}
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
/*
|
1066
|
+
Copyright 2017 Google Inc.
|
1067
|
+
|
1068
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1069
|
+
you may not use this file except in compliance with the License.
|
1070
|
+
You may obtain a copy of the License at
|
1071
|
+
|
1072
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
1073
|
+
|
1074
|
+
Unless required by applicable law or agreed to in writing, software
|
1075
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1076
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1077
|
+
See the License for the specific language governing permissions and
|
1078
|
+
limitations under the License.
|
1079
|
+
*/
|
1080
|
+
|
1081
|
+
var publicAPI = /*#__PURE__*/Object.freeze({
|
1082
|
+
CacheFirst: CacheFirst,
|
1083
|
+
CacheOnly: CacheOnly,
|
1084
|
+
NetworkFirst: NetworkFirst,
|
1085
|
+
NetworkOnly: NetworkOnly,
|
1086
|
+
StaleWhileRevalidate: StaleWhileRevalidate
|
1087
|
+
});
|
1088
|
+
|
1089
|
+
/*
|
1090
|
+
Copyright 2016 Google Inc. All Rights Reserved.
|
1091
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1092
|
+
you may not use this file except in compliance with the License.
|
1093
|
+
You may obtain a copy of the License at
|
1094
|
+
|
1095
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1096
|
+
|
1097
|
+
Unless required by applicable law or agreed to in writing, software
|
1098
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1099
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1100
|
+
See the License for the specific language governing permissions and
|
1101
|
+
limitations under the License.
|
1102
|
+
*/
|
1103
|
+
|
1104
|
+
/**
|
1105
|
+
* @function workbox.strategies.cacheFirst
|
1106
|
+
* @param {Object} options See the {@link workbox.strategies.CacheFirst}
|
1107
|
+
* constructor for more info.
|
1108
|
+
*/
|
1109
|
+
|
1110
|
+
/**
|
1111
|
+
* @function workbox.strategies.cacheOnly
|
1112
|
+
* @param {Object} options See the {@link workbox.strategies.CacheOnly}
|
1113
|
+
* constructor for more info.
|
1114
|
+
*/
|
1115
|
+
|
1116
|
+
/**
|
1117
|
+
* @function workbox.strategies.networkFirst
|
1118
|
+
* @param {Object} options See the {@link workbox.strategies.NetworkFirst}
|
1119
|
+
* constructor for more info.
|
1120
|
+
*/
|
1121
|
+
|
1122
|
+
/**
|
1123
|
+
* @function workbox.strategies.networkOnly
|
1124
|
+
* @param {Object} options See the {@link workbox.strategies.NetworkOnly}
|
1125
|
+
* constructor for more info.
|
1126
|
+
*/
|
1127
|
+
|
1128
|
+
/**
|
1129
|
+
* @function workbox.strategies.staleWhileRevalidate
|
1130
|
+
* @param {Object} options See the
|
1131
|
+
* {@link workbox.strategies.StaleWhileRevalidate} constructor for more info.
|
1132
|
+
*/
|
1133
|
+
|
1134
|
+
const mapping = {
|
1135
|
+
cacheFirst: CacheFirst,
|
1136
|
+
cacheOnly: CacheOnly,
|
1137
|
+
networkFirst: NetworkFirst,
|
1138
|
+
networkOnly: NetworkOnly,
|
1139
|
+
staleWhileRevalidate: StaleWhileRevalidate
|
1140
|
+
};
|
1141
|
+
|
1142
|
+
const defaultExport = {};
|
1143
|
+
Object.keys(mapping).forEach(keyName => {
|
1144
|
+
defaultExport[keyName] = (options = {}) => {
|
1145
|
+
const StrategyClass = mapping[keyName];
|
1146
|
+
return new StrategyClass(Object.assign(options));
|
1147
|
+
};
|
1148
|
+
});
|
1149
|
+
|
1150
|
+
/*
|
1151
|
+
Copyright 2017 Google Inc.
|
1152
|
+
|
1153
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1154
|
+
you may not use this file except in compliance with the License.
|
1155
|
+
You may obtain a copy of the License at
|
1156
|
+
|
1157
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
1158
|
+
|
1159
|
+
Unless required by applicable law or agreed to in writing, software
|
1160
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1161
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1162
|
+
See the License for the specific language governing permissions and
|
1163
|
+
limitations under the License.
|
1164
|
+
*/
|
1165
|
+
|
1166
|
+
const finalExport = Object.assign(defaultExport, publicAPI);
|
1167
|
+
|
1168
|
+
return finalExport;
|
1169
|
+
|
1170
|
+
}(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private));
|
1171
|
+
|
1172
|
+
//# sourceMappingURL=workbox-strategies.dev.js.map
|