jekyll-pwa-plugin 2.0.1 → 5.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +5 -5
  2. data/lib/jekyll-pwa-plugin.rb +12 -4
  3. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.dev.js +818 -0
  4. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.dev.js.map +1 -0
  5. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.prod.js +2 -0
  6. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.prod.js.map +1 -0
  7. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.dev.js +288 -0
  8. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.dev.js.map +1 -0
  9. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.prod.js +2 -0
  10. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.prod.js.map +1 -0
  11. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.dev.js +191 -0
  12. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.dev.js.map +1 -0
  13. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.prod.js +2 -0
  14. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.prod.js.map +1 -0
  15. data/lib/vendor/workbox-v5.1.4/workbox-core.dev.js +1858 -0
  16. data/lib/vendor/workbox-v5.1.4/workbox-core.dev.js.map +1 -0
  17. data/lib/vendor/workbox-v5.1.4/workbox-core.prod.js +2 -0
  18. data/lib/vendor/workbox-v5.1.4/workbox-core.prod.js.map +1 -0
  19. data/lib/vendor/workbox-v5.1.4/workbox-expiration.dev.js +649 -0
  20. data/lib/vendor/workbox-v5.1.4/workbox-expiration.dev.js.map +1 -0
  21. data/lib/vendor/workbox-v5.1.4/workbox-expiration.prod.js +2 -0
  22. data/lib/vendor/workbox-v5.1.4/workbox-expiration.prod.js.map +1 -0
  23. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.dev.js +102 -0
  24. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.dev.js.map +1 -0
  25. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.prod.js +2 -0
  26. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.prod.js.map +1 -0
  27. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.dev.js +235 -0
  28. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.dev.js.map +1 -0
  29. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.prod.js +2 -0
  30. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.prod.js.map +1 -0
  31. data/lib/vendor/workbox-v5.1.4/workbox-precaching.dev.js +1210 -0
  32. data/lib/vendor/workbox-v5.1.4/workbox-precaching.dev.js.map +1 -0
  33. data/lib/vendor/workbox-v5.1.4/workbox-precaching.prod.js +2 -0
  34. data/lib/vendor/workbox-v5.1.4/workbox-precaching.prod.js.map +1 -0
  35. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.dev.js +262 -0
  36. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.dev.js.map +1 -0
  37. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.prod.js +2 -0
  38. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.prod.js.map +1 -0
  39. data/lib/vendor/workbox-v5.1.4/workbox-routing.dev.js +923 -0
  40. data/lib/vendor/workbox-v5.1.4/workbox-routing.dev.js.map +1 -0
  41. data/lib/vendor/workbox-v5.1.4/workbox-routing.prod.js +2 -0
  42. data/lib/vendor/workbox-v5.1.4/workbox-routing.prod.js.map +1 -0
  43. data/lib/vendor/workbox-v5.1.4/workbox-strategies.dev.js +923 -0
  44. data/lib/vendor/workbox-v5.1.4/workbox-strategies.dev.js.map +1 -0
  45. data/lib/vendor/workbox-v5.1.4/workbox-strategies.prod.js +2 -0
  46. data/lib/vendor/workbox-v5.1.4/workbox-strategies.prod.js.map +1 -0
  47. data/lib/vendor/workbox-v5.1.4/workbox-streams.dev.js +318 -0
  48. data/lib/vendor/workbox-v5.1.4/workbox-streams.dev.js.map +1 -0
  49. data/lib/vendor/workbox-v5.1.4/workbox-streams.prod.js +2 -0
  50. data/lib/vendor/workbox-v5.1.4/workbox-streams.prod.js.map +1 -0
  51. data/lib/vendor/workbox-v5.1.4/workbox-sw.js +2 -0
  52. data/lib/vendor/workbox-v5.1.4/workbox-sw.js.map +1 -0
  53. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.es5.mjs +1125 -0
  54. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.es5.mjs.map +1 -0
  55. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.mjs +943 -0
  56. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.mjs.map +1 -0
  57. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.umd.js +1136 -0
  58. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.umd.js.map +1 -0
  59. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.es5.mjs +2 -0
  60. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.es5.mjs.map +1 -0
  61. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.mjs +2 -0
  62. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.mjs.map +1 -0
  63. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.umd.js +2 -0
  64. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.umd.js.map +1 -0
  65. metadata +65 -50
  66. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.dev.js +0 -593
  67. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.dev.js.map +0 -1
  68. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.prod.js +0 -3
  69. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.prod.js.map +0 -1
  70. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.dev.js +0 -395
  71. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.dev.js.map +0 -1
  72. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.prod.js +0 -3
  73. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.prod.js.map +0 -1
  74. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.dev.js +0 -740
  75. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.dev.js.map +0 -1
  76. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.prod.js +0 -3
  77. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.prod.js.map +0 -1
  78. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.dev.js +0 -236
  79. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.dev.js.map +0 -1
  80. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.prod.js +0 -3
  81. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.prod.js.map +0 -1
  82. data/lib/vendor/workbox-v3.3.1/workbox-core.dev.js +0 -1690
  83. data/lib/vendor/workbox-v3.3.1/workbox-core.dev.js.map +0 -1
  84. data/lib/vendor/workbox-v3.3.1/workbox-core.prod.js +0 -3
  85. data/lib/vendor/workbox-v3.3.1/workbox-core.prod.js.map +0 -1
  86. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.dev.js +0 -255
  87. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.dev.js.map +0 -1
  88. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.prod.js +0 -3
  89. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.prod.js.map +0 -1
  90. data/lib/vendor/workbox-v3.3.1/workbox-precaching.dev.js +0 -1149
  91. data/lib/vendor/workbox-v3.3.1/workbox-precaching.dev.js.map +0 -1
  92. data/lib/vendor/workbox-v3.3.1/workbox-precaching.prod.js +0 -3
  93. data/lib/vendor/workbox-v3.3.1/workbox-precaching.prod.js.map +0 -1
  94. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.dev.js +0 -299
  95. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.dev.js.map +0 -1
  96. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.prod.js +0 -3
  97. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.prod.js.map +0 -1
  98. data/lib/vendor/workbox-v3.3.1/workbox-routing.dev.js +0 -863
  99. data/lib/vendor/workbox-v3.3.1/workbox-routing.dev.js.map +0 -1
  100. data/lib/vendor/workbox-v3.3.1/workbox-routing.prod.js +0 -3
  101. data/lib/vendor/workbox-v3.3.1/workbox-routing.prod.js.map +0 -1
  102. data/lib/vendor/workbox-v3.3.1/workbox-strategies.dev.js +0 -1091
  103. data/lib/vendor/workbox-v3.3.1/workbox-strategies.dev.js.map +0 -1
  104. data/lib/vendor/workbox-v3.3.1/workbox-strategies.prod.js +0 -3
  105. data/lib/vendor/workbox-v3.3.1/workbox-strategies.prod.js.map +0 -1
  106. data/lib/vendor/workbox-v3.3.1/workbox-streams.dev.js +0 -390
  107. data/lib/vendor/workbox-v3.3.1/workbox-streams.dev.js.map +0 -1
  108. data/lib/vendor/workbox-v3.3.1/workbox-streams.prod.js +0 -3
  109. data/lib/vendor/workbox-v3.3.1/workbox-streams.prod.js.map +0 -1
  110. data/lib/vendor/workbox-v3.3.1/workbox-sw.js +0 -3
  111. data/lib/vendor/workbox-v3.3.1/workbox-sw.js.map +0 -1
@@ -1 +0,0 @@
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.3.1'] = 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', '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} input\n * @param {FetchEvent} input.event\n * @param {URL} input.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"}
@@ -1,3 +0,0 @@
1
- this.workbox=this.workbox||{},this.workbox.routing=function(t,e){"use strict";try{self.workbox.v["workbox:routing:3.3.1"]=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
@@ -1 +0,0 @@
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.3.1\"]=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"}
@@ -1,1091 +0,0 @@
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.3.1'] = 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
- */
80
- constructor(options = {}) {
81
- this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
82
- this._plugins = options.plugins || [];
83
- this._fetchOptions = options.fetchOptions || null;
84
- }
85
-
86
- /**
87
- * This method will perform a request strategy and follows an API that
88
- * will work with the
89
- * [Workbox Router]{@link workbox.routing.Router}.
90
- *
91
- * @param {Object} input
92
- * @param {FetchEvent} input.event The fetch event to run this strategy
93
- * against.
94
- * @return {Promise<Response>}
95
- */
96
- handle({ event }) {
97
- var _this = this;
98
-
99
- return babelHelpers.asyncToGenerator(function* () {
100
- {
101
- assert_mjs.assert.isInstance(event, FetchEvent, {
102
- moduleName: 'workbox-strategies',
103
- className: 'CacheFirst',
104
- funcName: 'handle',
105
- paramName: 'event'
106
- });
107
- }
108
-
109
- return _this.makeRequest({
110
- event,
111
- request: event.request
112
- });
113
- })();
114
- }
115
-
116
- /**
117
- * This method can be used to perform a make a standalone request outside the
118
- * context of the [Workbox Router]{@link workbox.routing.Router}.
119
- *
120
- * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
121
- * for more usage information.
122
- *
123
- * @param {Object} input
124
- * @param {Request|string} input.request Either a
125
- * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
126
- * object, or a string URL, corresponding to the request to be made.
127
- * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
128
- * called automatically to extend the service worker's lifetime.
129
- * @return {Promise<Response>}
130
- */
131
- makeRequest({ event, request }) {
132
- var _this2 = this;
133
-
134
- return babelHelpers.asyncToGenerator(function* () {
135
- const logs = [];
136
-
137
- if (typeof request === 'string') {
138
- request = new Request(request);
139
- }
140
-
141
- {
142
- assert_mjs.assert.isInstance(request, Request, {
143
- moduleName: 'workbox-strategies',
144
- className: 'CacheFirst',
145
- funcName: 'makeRequest',
146
- paramName: 'request'
147
- });
148
- }
149
-
150
- let response = yield cacheWrapper_mjs.cacheWrapper.match(_this2._cacheName, request, null, _this2._plugins);
151
-
152
- let error;
153
- if (!response) {
154
- {
155
- logs.push(`No response found in the '${_this2._cacheName}' cache. ` + `Will respond with a network request.`);
156
- }
157
- try {
158
- response = yield _this2._getFromNetwork(request, event);
159
- } catch (err) {
160
- error = err;
161
- }
162
-
163
- {
164
- if (response) {
165
- logs.push(`Got response from network.`);
166
- } else {
167
- logs.push(`Unable to get a response from the network.`);
168
- }
169
- }
170
- } else {
171
- {
172
- logs.push(`Found a cached response in the '${_this2._cacheName}' cache.`);
173
- }
174
- }
175
-
176
- {
177
- logger_mjs.logger.groupCollapsed(messages.strategyStart('CacheFirst', request));
178
- for (let log of logs) {
179
- logger_mjs.logger.log(log);
180
- }
181
- messages.printFinalResponse(response);
182
- logger_mjs.logger.groupEnd();
183
- }
184
-
185
- if (error) {
186
- // Don't swallow error as we'll want it to throw and enable catch
187
- // handlers in router.
188
- throw error;
189
- }
190
-
191
- return response;
192
- })();
193
- }
194
-
195
- /**
196
- * Handles the network and cache part of CacheFirst.
197
- *
198
- * @param {Request} request
199
- * @param {FetchEvent} [event]
200
- * @return {Promise<Response>}
201
- *
202
- * @private
203
- */
204
- _getFromNetwork(request, event) {
205
- var _this3 = this;
206
-
207
- return babelHelpers.asyncToGenerator(function* () {
208
- const response = yield fetchWrapper_mjs.fetchWrapper.fetch(request, _this3._fetchOptions, _this3._plugins);
209
-
210
- // Keep the service worker while we put the request to the cache
211
- const responseClone = response.clone();
212
- const cachePutPromise = cacheWrapper_mjs.cacheWrapper.put(_this3._cacheName, request, responseClone, _this3._plugins);
213
-
214
- if (event) {
215
- try {
216
- event.waitUntil(cachePutPromise);
217
- } catch (error) {
218
- {
219
- logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
220
- }
221
- }
222
- }
223
-
224
- return response;
225
- })();
226
- }
227
- }
228
-
229
- /*
230
- Copyright 2018 Google Inc. All Rights Reserved.
231
- Licensed under the Apache License, Version 2.0 (the "License");
232
- you may not use this file except in compliance with the License.
233
- You may obtain a copy of the License at
234
-
235
- http://www.apache.org/licenses/LICENSE-2.0
236
-
237
- Unless required by applicable law or agreed to in writing, software
238
- distributed under the License is distributed on an "AS IS" BASIS,
239
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
240
- See the License for the specific language governing permissions and
241
- limitations under the License.
242
- */
243
-
244
- /**
245
- * An implementation of a
246
- * [cache-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-only}
247
- * request strategy.
248
- *
249
- * 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}.
250
- *
251
- * @memberof workbox.strategies
252
- */
253
- class CacheOnly {
254
- /**
255
- * @param {Object} options
256
- * @param {string} options.cacheName Cache name to store and retrieve
257
- * requests. Defaults to cache names provided by
258
- * [workbox-core]{@link workbox.core.cacheNames}.
259
- * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
260
- * to use in conjunction with this caching strategy.
261
- */
262
- constructor(options = {}) {
263
- this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
264
- this._plugins = options.plugins || [];
265
- }
266
-
267
- /**
268
- * This method will perform a request strategy and follows an API that
269
- * will work with the
270
- * [Workbox Router]{@link workbox.routing.Router}.
271
- *
272
- * @param {Object} input
273
- * @param {FetchEvent} input.event The fetch event to run this strategy
274
- * against.
275
- * @return {Promise<Response>}
276
- */
277
- handle({ event }) {
278
- var _this = this;
279
-
280
- return babelHelpers.asyncToGenerator(function* () {
281
- {
282
- assert_mjs.assert.isInstance(event, FetchEvent, {
283
- moduleName: 'workbox-strategies',
284
- className: 'CacheOnly',
285
- funcName: 'handle',
286
- paramName: 'event'
287
- });
288
- }
289
-
290
- return _this.makeRequest({
291
- event,
292
- request: event.request
293
- });
294
- })();
295
- }
296
-
297
- /**
298
- * This method can be used to perform a make a standalone request outside the
299
- * context of the [Workbox Router]{@link workbox.routing.Router}.
300
- *
301
- * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
302
- * for more usage information.
303
- *
304
- * @param {Object} input
305
- * @param {Request|string} input.request Either a
306
- * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
307
- * object, or a string URL, corresponding to the request to be made.
308
- * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
309
- * called automatically to extend the service worker's lifetime.
310
- * @return {Promise<Response>}
311
- */
312
- makeRequest({ event, request }) {
313
- var _this2 = this;
314
-
315
- return babelHelpers.asyncToGenerator(function* () {
316
- if (typeof request === 'string') {
317
- request = new Request(request);
318
- }
319
-
320
- {
321
- assert_mjs.assert.isInstance(request, Request, {
322
- moduleName: 'workbox-strategies',
323
- className: 'CacheOnly',
324
- funcName: 'makeRequest',
325
- paramName: 'request'
326
- });
327
- }
328
-
329
- const response = yield cacheWrapper_mjs.cacheWrapper.match(_this2._cacheName, request, null, _this2._plugins);
330
-
331
- {
332
- logger_mjs.logger.groupCollapsed(messages.strategyStart('CacheOnly', request));
333
- if (response) {
334
- logger_mjs.logger.log(`Found a cached response in the '${_this2._cacheName}'` + ` cache.`);
335
- messages.printFinalResponse(response);
336
- } else {
337
- logger_mjs.logger.log(`No response found in the '${_this2._cacheName}' cache.`);
338
- }
339
- logger_mjs.logger.groupEnd();
340
- }
341
-
342
- return response;
343
- })();
344
- }
345
- }
346
-
347
- /*
348
- Copyright 2016 Google Inc. All Rights Reserved.
349
- Licensed under the Apache License, Version 2.0 (the "License");
350
- you may not use this file except in compliance with the License.
351
- You may obtain a copy of the License at
352
-
353
- http://www.apache.org/licenses/LICENSE-2.0
354
-
355
- Unless required by applicable law or agreed to in writing, software
356
- distributed under the License is distributed on an "AS IS" BASIS,
357
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
358
- See the License for the specific language governing permissions and
359
- limitations under the License.
360
- */
361
-
362
- var cacheOkAndOpaquePlugin = {
363
- /**
364
- * Return return a response (i.e. allow caching) if the
365
- * response is ok (i.e. 200) or is opaque.
366
- *
367
- * @param {Object} input
368
- * @param {Response} input.response
369
- * @return {Response|null}
370
- *
371
- * @private
372
- */
373
- cacheWillUpdate: ({ response }) => {
374
- if (response.ok || response.status === 0) {
375
- return response;
376
- }
377
- return null;
378
- }
379
- };
380
-
381
- /*
382
- Copyright 2018 Google Inc. All Rights Reserved.
383
- Licensed under the Apache License, Version 2.0 (the "License");
384
- you may not use this file except in compliance with the License.
385
- You may obtain a copy of the License at
386
-
387
- http://www.apache.org/licenses/LICENSE-2.0
388
-
389
- Unless required by applicable law or agreed to in writing, software
390
- distributed under the License is distributed on an "AS IS" BASIS,
391
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
392
- See the License for the specific language governing permissions and
393
- limitations under the License.
394
- */
395
-
396
- /**
397
- * An implementation of a
398
- * [network first]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-falling-back-to-cache}
399
- * request strategy.
400
- *
401
- * By default, this strategy will cache responses with a 200 status code as
402
- * well as [opaque responses]{@link https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests}.
403
- * Opaque responses are are cross-origin requests where the response doesn't
404
- * support [CORS]{@link https://enable-cors.org/}.
405
- *
406
- * @memberof workbox.strategies
407
- */
408
- class NetworkFirst {
409
- /**
410
- * @param {Object} options
411
- * @param {string} options.cacheName Cache name to store and retrieve
412
- * requests. Defaults to cache names provided by
413
- * [workbox-core]{@link workbox.core.cacheNames}.
414
- * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
415
- * to use in conjunction with this caching strategy.
416
- * @param {Object} options.fetchOptions Values passed along to the
417
- * [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
418
- * of all fetch() requests made by this strategy.
419
- * @param {number} options.networkTimeoutSeconds If set, any network requests
420
- * that fail to respond within the timeout will fallback to the cache.
421
- *
422
- * This option can be used to combat
423
- * "[lie-fi]{@link https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi}"
424
- * scenarios.
425
- */
426
- constructor(options = {}) {
427
- this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
428
-
429
- if (options.plugins) {
430
- let isUsingCacheWillUpdate = options.plugins.some(plugin => !!plugin.cacheWillUpdate);
431
- this._plugins = isUsingCacheWillUpdate ? options.plugins : [cacheOkAndOpaquePlugin, ...options.plugins];
432
- } else {
433
- // No plugins passed in, use the default plugin.
434
- this._plugins = [cacheOkAndOpaquePlugin];
435
- }
436
-
437
- this._networkTimeoutSeconds = options.networkTimeoutSeconds;
438
- {
439
- if (this._networkTimeoutSeconds) {
440
- assert_mjs.assert.isType(this._networkTimeoutSeconds, 'number', {
441
- moduleName: 'workbox-strategies',
442
- className: 'NetworkFirst',
443
- funcName: 'constructor',
444
- paramName: 'networkTimeoutSeconds'
445
- });
446
- }
447
- }
448
-
449
- this._fetchOptions = options.fetchOptions || null;
450
- }
451
-
452
- /**
453
- * This method will perform a request strategy and follows an API that
454
- * will work with the
455
- * [Workbox Router]{@link workbox.routing.Router}.
456
- *
457
- * @param {Object} input
458
- * @param {FetchEvent} input.event The fetch event to run this strategy
459
- * against.
460
- * @return {Promise<Response>}
461
- */
462
- handle({ event }) {
463
- var _this = this;
464
-
465
- return babelHelpers.asyncToGenerator(function* () {
466
- {
467
- assert_mjs.assert.isInstance(event, FetchEvent, {
468
- moduleName: 'workbox-strategies',
469
- className: 'NetworkFirst',
470
- funcName: 'handle',
471
- paramName: 'event'
472
- });
473
- }
474
-
475
- return _this.makeRequest({
476
- event,
477
- request: event.request
478
- });
479
- })();
480
- }
481
-
482
- /**
483
- * This method can be used to perform a make a standalone request outside the
484
- * context of the [Workbox Router]{@link workbox.routing.Router}.
485
- *
486
- * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
487
- * for more usage information.
488
- *
489
- * @param {Object} input
490
- * @param {Request|string} input.request Either a
491
- * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
492
- * object, or a string URL, corresponding to the request to be made.
493
- * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
494
- * called automatically to extend the service worker's lifetime.
495
- * @return {Promise<Response>}
496
- */
497
- makeRequest({ event, request }) {
498
- var _this2 = this;
499
-
500
- return babelHelpers.asyncToGenerator(function* () {
501
- const logs = [];
502
-
503
- if (typeof request === 'string') {
504
- request = new Request(request);
505
- }
506
-
507
- {
508
- assert_mjs.assert.isInstance(request, Request, {
509
- moduleName: 'workbox-strategies',
510
- className: 'NetworkFirst',
511
- funcName: 'handle',
512
- paramName: 'makeRequest'
513
- });
514
- }
515
-
516
- const promises = [];
517
- let timeoutId;
518
-
519
- if (_this2._networkTimeoutSeconds) {
520
- const { id, promise } = _this2._getTimeoutPromise(request, logs);
521
- timeoutId = id;
522
- promises.push(promise);
523
- }
524
-
525
- const networkPromise = _this2._getNetworkPromise(timeoutId, event, request, logs);
526
- promises.push(networkPromise);
527
-
528
- // Promise.race() will resolve as soon as the first promise resolves.
529
- let response = yield Promise.race(promises);
530
- // If Promise.race() resolved with null, it might be due to a network
531
- // timeout + a cache miss. If that were to happen, we'd rather wait until
532
- // the networkPromise resolves instead of returning null.
533
- // Note that it's fine to await an already-resolved promise, so we don't
534
- // have to check to see if it's still "in flight".
535
- if (!response) {
536
- response = yield networkPromise;
537
- }
538
-
539
- {
540
- logger_mjs.logger.groupCollapsed(messages.strategyStart('NetworkFirst', request));
541
- for (let log of logs) {
542
- logger_mjs.logger.log(log);
543
- }
544
- messages.printFinalResponse(response);
545
- logger_mjs.logger.groupEnd();
546
- }
547
-
548
- return response;
549
- })();
550
- }
551
-
552
- /**
553
- * @param {Request} request
554
- * @param {Array} logs A reference to the logs array
555
- * @return {Promise<Response>}
556
- *
557
- * @private
558
- */
559
- _getTimeoutPromise(request, logs) {
560
- var _this3 = this;
561
-
562
- let timeoutId;
563
- const timeoutPromise = new Promise(resolve => {
564
- const onNetworkTimeout = (() => {
565
- var _ref = babelHelpers.asyncToGenerator(function* () {
566
- {
567
- logs.push(`Timing out the network response at ` + `${_this3._networkTimeoutSeconds} seconds.`);
568
- }
569
-
570
- resolve((yield _this3._respondFromCache(request)));
571
- });
572
-
573
- return function onNetworkTimeout() {
574
- return _ref.apply(this, arguments);
575
- };
576
- })();
577
-
578
- timeoutId = setTimeout(onNetworkTimeout, this._networkTimeoutSeconds * 1000);
579
- });
580
-
581
- return {
582
- promise: timeoutPromise,
583
- id: timeoutId
584
- };
585
- }
586
-
587
- /**
588
- * @param {number} timeoutId
589
- * @param {FetchEvent|null} event
590
- * @param {Request} request
591
- * @param {Array} logs A reference to the logs Array.
592
- * @return {Promise<Response>}
593
- *
594
- * @private
595
- */
596
- _getNetworkPromise(timeoutId, event, request, logs) {
597
- var _this4 = this;
598
-
599
- return babelHelpers.asyncToGenerator(function* () {
600
- let error;
601
- let response;
602
- try {
603
- response = yield fetchWrapper_mjs.fetchWrapper.fetch(request, _this4._fetchOptions, _this4._plugins);
604
- } catch (err) {
605
- error = err;
606
- }
607
-
608
- if (timeoutId) {
609
- clearTimeout(timeoutId);
610
- }
611
-
612
- {
613
- if (response) {
614
- logs.push(`Got response from network.`);
615
- } else {
616
- logs.push(`Unable to get a response from the network. Will respond ` + `with a cached response.`);
617
- }
618
- }
619
-
620
- if (error || !response) {
621
- response = yield _this4._respondFromCache(request);
622
- {
623
- if (response) {
624
- logs.push(`Found a cached response in the '${_this4._cacheName}'` + ` cache.`);
625
- } else {
626
- logs.push(`No response found in the '${_this4._cacheName}' cache.`);
627
- }
628
- }
629
- } else {
630
- // Keep the service worker alive while we put the request in the cache
631
- const responseClone = response.clone();
632
- const cachePut = cacheWrapper_mjs.cacheWrapper.put(_this4._cacheName, request, responseClone, _this4._plugins);
633
-
634
- if (event) {
635
- try {
636
- // The event has been responded to so we can keep the SW alive to
637
- // respond to the request
638
- event.waitUntil(cachePut);
639
- } catch (err) {
640
- {
641
- logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
642
- }
643
- }
644
- }
645
- }
646
-
647
- return response;
648
- })();
649
- }
650
-
651
- /**
652
- * Used if the network timeouts or fails to make the request.
653
- *
654
- * @param {Request} request The fetchEvent request to match in the cache
655
- * @return {Promise<Object>}
656
- *
657
- * @private
658
- */
659
- _respondFromCache(request) {
660
- return cacheWrapper_mjs.cacheWrapper.match(this._cacheName, request, null, this._plugins);
661
- }
662
- }
663
-
664
- /*
665
- Copyright 2018 Google Inc. All Rights Reserved.
666
- Licensed under the Apache License, Version 2.0 (the "License");
667
- you may not use this file except in compliance with the License.
668
- You may obtain a copy of the License at
669
-
670
- http://www.apache.org/licenses/LICENSE-2.0
671
-
672
- Unless required by applicable law or agreed to in writing, software
673
- distributed under the License is distributed on an "AS IS" BASIS,
674
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
675
- See the License for the specific language governing permissions and
676
- limitations under the License.
677
- */
678
-
679
- /**
680
- * An implementation of a
681
- * [network-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-only}
682
- * request strategy.
683
- *
684
- * 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}.
685
- *
686
- * @memberof workbox.strategies
687
- */
688
- class NetworkOnly {
689
- /**
690
- * @param {Object} options
691
- * @param {string} options.cacheName Cache name to store and retrieve
692
- * requests. Defaults to cache names provided by
693
- * [workbox-core]{@link workbox.core.cacheNames}.
694
- * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
695
- * to use in conjunction with this caching strategy.
696
- * @param {Object} options.fetchOptions Values passed along to the
697
- * [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
698
- * of all fetch() requests made by this strategy.
699
- */
700
- constructor(options = {}) {
701
- this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
702
- this._plugins = options.plugins || [];
703
- this._fetchOptions = options.fetchOptions || null;
704
- }
705
-
706
- /**
707
- * This method will perform a request strategy and follows an API that
708
- * will work with the
709
- * [Workbox Router]{@link workbox.routing.Router}.
710
- *
711
- * @param {Object} input
712
- * @param {FetchEvent} input.event The fetch event to run this strategy
713
- * against.
714
- * @return {Promise<Response>}
715
- */
716
- handle({ event }) {
717
- var _this = this;
718
-
719
- return babelHelpers.asyncToGenerator(function* () {
720
- {
721
- assert_mjs.assert.isInstance(event, FetchEvent, {
722
- moduleName: 'workbox-strategies',
723
- className: 'NetworkOnly',
724
- funcName: 'handle',
725
- paramName: 'event'
726
- });
727
- }
728
-
729
- return _this.makeRequest({
730
- event,
731
- request: event.request
732
- });
733
- })();
734
- }
735
-
736
- /**
737
- * This method can be used to perform a make a standalone request outside the
738
- * context of the [Workbox Router]{@link workbox.routing.Router}.
739
- *
740
- * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
741
- * for more usage information.
742
- *
743
- * @param {Object} input
744
- * @param {Request|string} input.request Either a
745
- * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
746
- * object, or a string URL, corresponding to the request to be made.
747
- * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
748
- * called automatically to extend the service worker's lifetime.
749
- * @return {Promise<Response>}
750
- */
751
- makeRequest({ event, request }) {
752
- var _this2 = this;
753
-
754
- return babelHelpers.asyncToGenerator(function* () {
755
- if (typeof request === 'string') {
756
- request = new Request(request);
757
- }
758
-
759
- {
760
- assert_mjs.assert.isInstance(request, Request, {
761
- moduleName: 'workbox-strategies',
762
- className: 'NetworkOnly',
763
- funcName: 'handle',
764
- paramName: 'request'
765
- });
766
- }
767
-
768
- let error;
769
- let response;
770
- try {
771
- response = yield fetchWrapper_mjs.fetchWrapper.fetch(request, _this2._fetchOptions, _this2._plugins);
772
- } catch (err) {
773
- error = err;
774
- }
775
-
776
- {
777
- logger_mjs.logger.groupCollapsed(messages.strategyStart('NetworkOnly', request));
778
- if (response) {
779
- logger_mjs.logger.log(`Got response from network.`);
780
- } else {
781
- logger_mjs.logger.log(`Unable to get a response from the network.`);
782
- }
783
- messages.printFinalResponse(response);
784
- logger_mjs.logger.groupEnd();
785
- }
786
-
787
- // If there was an error thrown, re-throw it to ensure the Routers
788
- // catch handler is triggered.
789
- if (error) {
790
- throw error;
791
- }
792
-
793
- return response;
794
- })();
795
- }
796
- }
797
-
798
- /*
799
- Copyright 2018 Google Inc. All Rights Reserved.
800
- Licensed under the Apache License, Version 2.0 (the "License");
801
- you may not use this file except in compliance with the License.
802
- You may obtain a copy of the License at
803
-
804
- http://www.apache.org/licenses/LICENSE-2.0
805
-
806
- Unless required by applicable law or agreed to in writing, software
807
- distributed under the License is distributed on an "AS IS" BASIS,
808
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
809
- See the License for the specific language governing permissions and
810
- limitations under the License.
811
- */
812
-
813
- /**
814
- * An implementation of a
815
- * [stale-while-revalidate]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#stale-while-revalidate}
816
- * request strategy.
817
- *
818
- * Resources are requested from both the cache and the network in parallel.
819
- * The strategy will respond with the cached version if available, otherwise
820
- * wait for the network response. The cache is updated with the network response
821
- * with each successful request.
822
- *
823
- * By default, this strategy will cache responses with a 200 status code as
824
- * well as [opaque responses]{@link https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests}.
825
- * Opaque responses are are cross-origin requests where the response doesn't
826
- * support [CORS]{@link https://enable-cors.org/}.
827
- *
828
- * @memberof workbox.strategies
829
- */
830
- class StaleWhileRevalidate {
831
- /**
832
- * @param {Object} options
833
- * @param {string} options.cacheName Cache name to store and retrieve
834
- * requests. Defaults to cache names provided by
835
- * [workbox-core]{@link workbox.core.cacheNames}.
836
- * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
837
- * to use in conjunction with this caching strategy.
838
- * @param {Object} options.fetchOptions Values passed along to the
839
- * [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
840
- * of all fetch() requests made by this strategy.
841
- */
842
- constructor(options = {}) {
843
- this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
844
- this._plugins = options.plugins || [];
845
-
846
- if (options.plugins) {
847
- let isUsingCacheWillUpdate = options.plugins.some(plugin => !!plugin.cacheWillUpdate);
848
- this._plugins = isUsingCacheWillUpdate ? options.plugins : [cacheOkAndOpaquePlugin, ...options.plugins];
849
- } else {
850
- // No plugins passed in, use the default plugin.
851
- this._plugins = [cacheOkAndOpaquePlugin];
852
- }
853
-
854
- this._fetchOptions = options.fetchOptions || null;
855
- }
856
-
857
- /**
858
- * This method will perform a request strategy and follows an API that
859
- * will work with the
860
- * [Workbox Router]{@link workbox.routing.Router}.
861
- *
862
- * @param {Object} input
863
- * @param {FetchEvent} input.event The fetch event to run this strategy
864
- * against.
865
- * @return {Promise<Response>}
866
- */
867
- handle({ event }) {
868
- var _this = this;
869
-
870
- return babelHelpers.asyncToGenerator(function* () {
871
- {
872
- assert_mjs.assert.isInstance(event, FetchEvent, {
873
- moduleName: 'workbox-strategies',
874
- className: 'StaleWhileRevalidate',
875
- funcName: 'handle',
876
- paramName: 'event'
877
- });
878
- }
879
-
880
- return _this.makeRequest({
881
- event,
882
- request: event.request
883
- });
884
- })();
885
- }
886
-
887
- /**
888
- * This method can be used to perform a make a standalone request outside the
889
- * context of the [Workbox Router]{@link workbox.routing.Router}.
890
- *
891
- * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
892
- * for more usage information.
893
- *
894
- * @param {Object} input
895
- * @param {Request|string} input.request Either a
896
- * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
897
- * object, or a string URL, corresponding to the request to be made.
898
- * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
899
- * called automatically to extend the service worker's lifetime.
900
- * @return {Promise<Response>}
901
- */
902
- makeRequest({ event, request }) {
903
- var _this2 = this;
904
-
905
- return babelHelpers.asyncToGenerator(function* () {
906
- const logs = [];
907
-
908
- if (typeof request === 'string') {
909
- request = new Request(request);
910
- }
911
-
912
- {
913
- assert_mjs.assert.isInstance(request, Request, {
914
- moduleName: 'workbox-strategies',
915
- className: 'StaleWhileRevalidate',
916
- funcName: 'handle',
917
- paramName: 'request'
918
- });
919
- }
920
-
921
- const fetchAndCachePromise = _this2._getFromNetwork(request, event);
922
-
923
- let response = yield cacheWrapper_mjs.cacheWrapper.match(_this2._cacheName, request, null, _this2._plugins);
924
-
925
- if (response) {
926
- {
927
- logs.push(`Found a cached response in the '${_this2._cacheName}'` + ` cache. Will update with the network response in the background.`);
928
- }
929
-
930
- if (event) {
931
- try {
932
- event.waitUntil(fetchAndCachePromise);
933
- } catch (error) {
934
- {
935
- logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
936
- }
937
- }
938
- }
939
- } else {
940
- {
941
- logs.push(`No response found in the '${_this2._cacheName}' cache. ` + `Will wait for the network response.`);
942
- }
943
- response = yield fetchAndCachePromise;
944
- }
945
-
946
- {
947
- logger_mjs.logger.groupCollapsed(messages.strategyStart('StaleWhileRevalidate', request));
948
- for (let log of logs) {
949
- logger_mjs.logger.log(log);
950
- }
951
- messages.printFinalResponse(response);
952
- logger_mjs.logger.groupEnd();
953
- }
954
-
955
- return response;
956
- })();
957
- }
958
-
959
- /**
960
- * @param {Request} request
961
- * @param {FetchEvent} [event]
962
- * @return {Promise<Response>}
963
- *
964
- * @private
965
- */
966
- _getFromNetwork(request, event) {
967
- var _this3 = this;
968
-
969
- return babelHelpers.asyncToGenerator(function* () {
970
- const response = yield fetchWrapper_mjs.fetchWrapper.fetch(request, _this3._fetchOptions, _this3._plugins);
971
-
972
- const cachePutPromise = cacheWrapper_mjs.cacheWrapper.put(_this3._cacheName, request, response.clone(), _this3._plugins);
973
-
974
- if (event) {
975
- try {
976
- event.waitUntil(cachePutPromise);
977
- } catch (error) {
978
- {
979
- logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
980
- }
981
- }
982
- }
983
-
984
- return response;
985
- })();
986
- }
987
- }
988
-
989
- /*
990
- Copyright 2017 Google Inc.
991
-
992
- Licensed under the Apache License, Version 2.0 (the "License");
993
- you may not use this file except in compliance with the License.
994
- You may obtain a copy of the License at
995
-
996
- https://www.apache.org/licenses/LICENSE-2.0
997
-
998
- Unless required by applicable law or agreed to in writing, software
999
- distributed under the License is distributed on an "AS IS" BASIS,
1000
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1001
- See the License for the specific language governing permissions and
1002
- limitations under the License.
1003
- */
1004
-
1005
- var publicAPI = /*#__PURE__*/Object.freeze({
1006
- CacheFirst: CacheFirst,
1007
- CacheOnly: CacheOnly,
1008
- NetworkFirst: NetworkFirst,
1009
- NetworkOnly: NetworkOnly,
1010
- StaleWhileRevalidate: StaleWhileRevalidate
1011
- });
1012
-
1013
- /*
1014
- Copyright 2016 Google Inc. All Rights Reserved.
1015
- Licensed under the Apache License, Version 2.0 (the "License");
1016
- you may not use this file except in compliance with the License.
1017
- You may obtain a copy of the License at
1018
-
1019
- http://www.apache.org/licenses/LICENSE-2.0
1020
-
1021
- Unless required by applicable law or agreed to in writing, software
1022
- distributed under the License is distributed on an "AS IS" BASIS,
1023
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1024
- See the License for the specific language governing permissions and
1025
- limitations under the License.
1026
- */
1027
-
1028
- /**
1029
- * @function workbox.strategies.cacheFirst
1030
- * @param {workbox.strategies.StrategyOptions} options
1031
- */
1032
-
1033
- /**
1034
- * @function workbox.strategies.cacheOnly
1035
- * @param {workbox.strategies.StrategyOptions} options
1036
- */
1037
-
1038
- /**
1039
- * @function workbox.strategies.networkFirst
1040
- * @param {workbox.strategies.StrategyOptions} options
1041
- */
1042
-
1043
- /**
1044
- * @function workbox.strategies.networkOnly
1045
- * @param {workbox.strategies.StrategyOptions} options
1046
- */
1047
-
1048
- /**
1049
- * @function workbox.strategies.staleWhileRevalidate
1050
- * @param {workbox.strategies.StrategyOptions} options
1051
- */
1052
-
1053
- const mapping = {
1054
- cacheFirst: CacheFirst,
1055
- cacheOnly: CacheOnly,
1056
- networkFirst: NetworkFirst,
1057
- networkOnly: NetworkOnly,
1058
- staleWhileRevalidate: StaleWhileRevalidate
1059
- };
1060
-
1061
- const defaultExport = {};
1062
- Object.keys(mapping).forEach(keyName => {
1063
- defaultExport[keyName] = (options = {}) => {
1064
- const StrategyClass = mapping[keyName];
1065
- return new StrategyClass(Object.assign(options));
1066
- };
1067
- });
1068
-
1069
- /*
1070
- Copyright 2017 Google Inc.
1071
-
1072
- Licensed under the Apache License, Version 2.0 (the "License");
1073
- you may not use this file except in compliance with the License.
1074
- You may obtain a copy of the License at
1075
-
1076
- https://www.apache.org/licenses/LICENSE-2.0
1077
-
1078
- Unless required by applicable law or agreed to in writing, software
1079
- distributed under the License is distributed on an "AS IS" BASIS,
1080
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1081
- See the License for the specific language governing permissions and
1082
- limitations under the License.
1083
- */
1084
-
1085
- const finalExport = Object.assign(defaultExport, publicAPI);
1086
-
1087
- return finalExport;
1088
-
1089
- }(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private));
1090
-
1091
- //# sourceMappingURL=workbox-strategies.dev.js.map