jekyll-pwa-workbox 0.0.8 → 0.0.9

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pwa-workbox.rb +1 -1
  3. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-background-sync.dev.js +818 -818
  4. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-background-sync.dev.js.map +1 -1
  5. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-background-sync.prod.js +2 -2
  6. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-background-sync.prod.js.map +1 -1
  7. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-broadcast-update.dev.js +288 -288
  8. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-broadcast-update.dev.js.map +1 -1
  9. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-broadcast-update.prod.js +2 -2
  10. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-broadcast-update.prod.js.map +1 -1
  11. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-cacheable-response.dev.js +191 -191
  12. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-cacheable-response.dev.js.map +1 -1
  13. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-cacheable-response.prod.js +2 -2
  14. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-cacheable-response.prod.js.map +1 -1
  15. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-core.dev.js +1858 -1880
  16. data/lib/vendor/workbox-v5.1.3/workbox-core.dev.js.map +1 -0
  17. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-core.prod.js +2 -2
  18. data/lib/vendor/workbox-v5.1.3/workbox-core.prod.js.map +1 -0
  19. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-expiration.dev.js +649 -649
  20. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-expiration.dev.js.map +1 -1
  21. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-expiration.prod.js +2 -2
  22. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-expiration.prod.js.map +1 -1
  23. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-navigation-preload.dev.js +102 -102
  24. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-navigation-preload.dev.js.map +1 -1
  25. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-navigation-preload.prod.js +2 -2
  26. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-navigation-preload.prod.js.map +1 -1
  27. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-offline-ga.dev.js +235 -235
  28. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-offline-ga.dev.js.map +1 -1
  29. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-offline-ga.prod.js +2 -2
  30. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-offline-ga.prod.js.map +1 -1
  31. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-precaching.dev.js +1210 -1222
  32. data/lib/vendor/workbox-v5.1.3/workbox-precaching.dev.js.map +1 -0
  33. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-precaching.prod.js +2 -2
  34. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-precaching.prod.js.map +1 -1
  35. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-range-requests.dev.js +262 -262
  36. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-range-requests.dev.js.map +1 -1
  37. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-range-requests.prod.js +2 -2
  38. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-range-requests.prod.js.map +1 -1
  39. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-routing.dev.js +923 -923
  40. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-routing.dev.js.map +1 -1
  41. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-routing.prod.js +2 -2
  42. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-routing.prod.js.map +1 -1
  43. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-strategies.dev.js +923 -923
  44. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-strategies.dev.js.map +1 -1
  45. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-strategies.prod.js +2 -2
  46. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-strategies.prod.js.map +1 -1
  47. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-streams.dev.js +318 -318
  48. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-streams.dev.js.map +1 -1
  49. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-streams.prod.js +2 -2
  50. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-streams.prod.js.map +1 -1
  51. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-sw.js +2 -2
  52. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-sw.js.map +1 -1
  53. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.dev.es5.mjs +1094 -1094
  54. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.dev.es5.mjs.map +1 -1
  55. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.dev.mjs +943 -943
  56. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.dev.mjs.map +1 -1
  57. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.dev.umd.js +1105 -1105
  58. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.dev.umd.js.map +1 -1
  59. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.prod.es5.mjs +2 -2
  60. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.prod.es5.mjs.map +1 -1
  61. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.prod.mjs +2 -2
  62. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.prod.mjs.map +1 -1
  63. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.prod.umd.js +2 -2
  64. data/lib/vendor/{workbox-v5.1.1 → workbox-v5.1.3}/workbox-window.prod.umd.js.map +1 -1
  65. metadata +65 -65
  66. data/lib/vendor/workbox-v5.1.1/workbox-core.dev.js.map +0 -1
  67. data/lib/vendor/workbox-v5.1.1/workbox-core.prod.js.map +0 -1
  68. data/lib/vendor/workbox-v5.1.1/workbox-precaching.dev.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"workbox-offline-ga.dev.js","sources":["../_version.js","../utils/constants.js","../initialize.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:google-analytics:5.1.1'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport '../_version.js';\nexport const QUEUE_NAME = 'workbox-google-analytics';\nexport const MAX_RETENTION_TIME = 60 * 48; // Two days in minutes\nexport const GOOGLE_ANALYTICS_HOST = 'www.google-analytics.com';\nexport const GTM_HOST = 'www.googletagmanager.com';\nexport const ANALYTICS_JS_PATH = '/analytics.js';\nexport const GTAG_JS_PATH = '/gtag/js';\nexport const GTM_JS_PATH = '/gtm.js';\nexport const COLLECT_DEFAULT_PATH = '/collect';\n// This RegExp matches all known Measurement Protocol single-hit collect\n// endpoints. Most of the time the default path (/collect) is used, but\n// occasionally an experimental endpoint is used when testing new features,\n// (e.g. /r/collect or /j/collect)\nexport const COLLECT_PATHS_REGEX = /^\\/(\\w+\\/)?collect/;\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { BackgroundSyncPlugin } from 'workbox-background-sync/BackgroundSyncPlugin.js';\nimport { cacheNames } from 'workbox-core/_private/cacheNames.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Route } from 'workbox-routing/Route.js';\nimport { Router } from 'workbox-routing/Router.js';\nimport { NetworkFirst } from 'workbox-strategies/NetworkFirst.js';\nimport { NetworkOnly } from 'workbox-strategies/NetworkOnly.js';\nimport { QUEUE_NAME, MAX_RETENTION_TIME, GOOGLE_ANALYTICS_HOST, GTM_HOST, ANALYTICS_JS_PATH, GTAG_JS_PATH, GTM_JS_PATH, COLLECT_PATHS_REGEX, } from './utils/constants.js';\nimport './_version.js';\n/**\n * Creates the requestWillDequeue callback to be used with the background\n * sync plugin. The callback takes the failed request and adds the\n * `qt` param based on the current time, as well as applies any other\n * user-defined hit modifications.\n *\n * @param {Object} config See {@link module:workbox-google-analytics.initialize}.\n * @return {Function} The requestWillDequeue callback function.\n *\n * @private\n */\nconst createOnSyncCallback = (config) => {\n return async ({ queue }) => {\n let entry;\n while (entry = await queue.shiftRequest()) {\n const { request, timestamp } = entry;\n const url = new URL(request.url);\n try {\n // Measurement protocol requests can set their payload parameters in\n // either the URL query string (for GET requests) or the POST body.\n const params = request.method === 'POST' ?\n new URLSearchParams(await request.clone().text()) :\n url.searchParams;\n // Calculate the qt param, accounting for the fact that an existing\n // qt param may be present and should be updated rather than replaced.\n const originalHitTime = timestamp - (Number(params.get('qt')) || 0);\n const queueTime = Date.now() - originalHitTime;\n // Set the qt param prior to applying hitFilter or parameterOverrides.\n params.set('qt', String(queueTime));\n // Apply `parameterOverrides`, if set.\n if (config.parameterOverrides) {\n for (const param of Object.keys(config.parameterOverrides)) {\n const value = config.parameterOverrides[param];\n params.set(param, value);\n }\n }\n // Apply `hitFilter`, if set.\n if (typeof config.hitFilter === 'function') {\n config.hitFilter.call(null, params);\n }\n // Retry the fetch. Ignore URL search params from the URL as they're\n // now in the post body.\n await fetch(new Request(url.origin + url.pathname, {\n body: params.toString(),\n method: 'POST',\n mode: 'cors',\n credentials: 'omit',\n headers: { 'Content-Type': 'text/plain' },\n }));\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(url.href)}'` +\n `has been replayed`);\n }\n }\n catch (err) {\n await queue.unshiftRequest(entry);\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(url.href)}'` +\n `failed to replay, putting it back in the queue.`);\n }\n throw err;\n }\n }\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`All Google Analytics request successfully replayed; ` +\n `the queue is now empty!`);\n }\n };\n};\n/**\n * Creates GET and POST routes to catch failed Measurement Protocol hits.\n *\n * @param {BackgroundSyncPlugin} bgSyncPlugin\n * @return {Array<Route>} The created routes.\n *\n * @private\n */\nconst createCollectRoutes = (bgSyncPlugin) => {\n const match = ({ url }) => url.hostname === GOOGLE_ANALYTICS_HOST &&\n COLLECT_PATHS_REGEX.test(url.pathname);\n const handler = new NetworkOnly({\n plugins: [bgSyncPlugin],\n });\n return [\n new Route(match, handler, 'GET'),\n new Route(match, handler, 'POST'),\n ];\n};\n/**\n * Creates a route with a network first strategy for the analytics.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createAnalyticsJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GOOGLE_ANALYTICS_HOST &&\n url.pathname === ANALYTICS_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * Creates a route with a network first strategy for the gtag.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createGtagJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GTM_HOST &&\n url.pathname === GTAG_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * Creates a route with a network first strategy for the gtm.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createGtmJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GTM_HOST &&\n url.pathname === GTM_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * @param {Object=} [options]\n * @param {Object} [options.cacheName] The cache name to store and retrieve\n * analytics.js. Defaults to the cache names provided by `workbox-core`.\n * @param {Object} [options.parameterOverrides]\n * [Measurement Protocol parameters](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters),\n * expressed as key/value pairs, to be added to replayed Google Analytics\n * requests. This can be used to, e.g., set a custom dimension indicating\n * that the request was replayed.\n * @param {Function} [options.hitFilter] A function that allows you to modify\n * the hit parameters prior to replaying\n * the hit. The function is invoked with the original hit's URLSearchParams\n * object as its only argument.\n *\n * @memberof module:workbox-google-analytics\n */\nconst initialize = (options = {}) => {\n const cacheName = cacheNames.getGoogleAnalyticsName(options.cacheName);\n const bgSyncPlugin = new BackgroundSyncPlugin(QUEUE_NAME, {\n maxRetentionTime: MAX_RETENTION_TIME,\n onSync: createOnSyncCallback(options),\n });\n const routes = [\n createGtmJsRoute(cacheName),\n createAnalyticsJsRoute(cacheName),\n createGtagJsRoute(cacheName),\n ...createCollectRoutes(bgSyncPlugin),\n ];\n const router = new Router();\n for (const route of routes) {\n router.registerRoute(route);\n }\n router.addFetchListener();\n};\nexport { initialize, };\n"],"names":["self","_","e","QUEUE_NAME","MAX_RETENTION_TIME","GOOGLE_ANALYTICS_HOST","GTM_HOST","ANALYTICS_JS_PATH","GTAG_JS_PATH","GTM_JS_PATH","COLLECT_PATHS_REGEX","createOnSyncCallback","config","queue","entry","shiftRequest","request","timestamp","url","URL","params","method","URLSearchParams","clone","text","searchParams","originalHitTime","Number","get","queueTime","Date","now","set","String","parameterOverrides","param","Object","keys","value","hitFilter","call","fetch","Request","origin","pathname","body","toString","mode","credentials","headers","process","logger","log","getFriendlyURL","href","err","unshiftRequest","createCollectRoutes","bgSyncPlugin","match","hostname","test","handler","NetworkOnly","plugins","Route","createAnalyticsJsRoute","cacheName","NetworkFirst","createGtagJsRoute","createGtmJsRoute","initialize","options","cacheNames","getGoogleAnalyticsName","BackgroundSyncPlugin","maxRetentionTime","onSync","routes","router","Router","route","registerRoute","addFetchListener"],"mappings":";;;;IAEA,IAAI;IACAA,EAAAA,IAAI,CAAC,gCAAD,CAAJ,IAA0CC,CAAC,EAA3C;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICLV;;;;;;;AAOA,IACO,MAAMC,UAAU,GAAG,0BAAnB;AACP,IAAO,MAAMC,kBAAkB,GAAG,KAAK,EAAhC;;AACP,IAAO,MAAMC,qBAAqB,GAAG,0BAA9B;AACP,IAAO,MAAMC,QAAQ,GAAG,0BAAjB;AACP,IAAO,MAAMC,iBAAiB,GAAG,eAA1B;AACP,IAAO,MAAMC,YAAY,GAAG,UAArB;AACP,IAAO,MAAMC,WAAW,GAAG,SAApB;AACP,IAEA;IACA;IACA;;AACA,IAAO,MAAMC,mBAAmB,GAAG,oBAA5B;;ICpBP;;;;;;;AAOA,IAUA;;;;;;;;;;;;IAWA,MAAMC,oBAAoB,GAAIC,MAAD,IAAY;IACrC,SAAO,OAAO;IAAEC,IAAAA;IAAF,GAAP,KAAqB;IACxB,QAAIC,KAAJ;;IACA,WAA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IACjC,QAAML,SAAS,GAAGM,wBAAU,CAACC,sBAAX,CAAkCF,OAAO,CAACL,SAA1C,CAAlB;IACA,QAAMT,YAAY,GAAG,IAAIiB,4CAAJ,CAAyBxE,UAAzB,EAAqC;IACtDyE,IAAAA,gBAAgB,EAAExE,kBADoC;IAEtDyE,IAAAA,MAAM,EAAElE,oBAAoB,CAAC6D,OAAD;IAF0B,GAArC,CAArB;IAIA,QAAMM,MAAM,GAAG,CACXR,gBAAgB,CAACH,SAAD,CADL,EAEXD,sBAAsB,CAACC,SAAD,CAFX,EAGXE,iBAAiB,CAACF,SAAD,CAHN,EAIX,GAAGV,mBAAmB,CAACC,YAAD,CAJX,CAAf;IAMA,QAAMqB,MAAM,GAAG,IAAIC,gBAAJ,EAAf;;IACA,OAAK,MAAMC,KAAX,IAAoBH,MAApB,EAA4B;IACxBC,IAAAA,MAAM,CAACG,aAAP,CAAqBD,KAArB;IACH;;IACDF,EAAAA,MAAM,CAACI,gBAAP;IACH,CAjBD;;;;;;;;;;"}
1
+ {"version":3,"file":"workbox-offline-ga.dev.js","sources":["../_version.js","../utils/constants.js","../initialize.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:google-analytics:5.1.3'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport '../_version.js';\nexport const QUEUE_NAME = 'workbox-google-analytics';\nexport const MAX_RETENTION_TIME = 60 * 48; // Two days in minutes\nexport const GOOGLE_ANALYTICS_HOST = 'www.google-analytics.com';\nexport const GTM_HOST = 'www.googletagmanager.com';\nexport const ANALYTICS_JS_PATH = '/analytics.js';\nexport const GTAG_JS_PATH = '/gtag/js';\nexport const GTM_JS_PATH = '/gtm.js';\nexport const COLLECT_DEFAULT_PATH = '/collect';\n// This RegExp matches all known Measurement Protocol single-hit collect\n// endpoints. Most of the time the default path (/collect) is used, but\n// occasionally an experimental endpoint is used when testing new features,\n// (e.g. /r/collect or /j/collect)\nexport const COLLECT_PATHS_REGEX = /^\\/(\\w+\\/)?collect/;\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { BackgroundSyncPlugin } from 'workbox-background-sync/BackgroundSyncPlugin.js';\nimport { cacheNames } from 'workbox-core/_private/cacheNames.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Route } from 'workbox-routing/Route.js';\nimport { Router } from 'workbox-routing/Router.js';\nimport { NetworkFirst } from 'workbox-strategies/NetworkFirst.js';\nimport { NetworkOnly } from 'workbox-strategies/NetworkOnly.js';\nimport { QUEUE_NAME, MAX_RETENTION_TIME, GOOGLE_ANALYTICS_HOST, GTM_HOST, ANALYTICS_JS_PATH, GTAG_JS_PATH, GTM_JS_PATH, COLLECT_PATHS_REGEX, } from './utils/constants.js';\nimport './_version.js';\n/**\n * Creates the requestWillDequeue callback to be used with the background\n * sync plugin. The callback takes the failed request and adds the\n * `qt` param based on the current time, as well as applies any other\n * user-defined hit modifications.\n *\n * @param {Object} config See {@link module:workbox-google-analytics.initialize}.\n * @return {Function} The requestWillDequeue callback function.\n *\n * @private\n */\nconst createOnSyncCallback = (config) => {\n return async ({ queue }) => {\n let entry;\n while (entry = await queue.shiftRequest()) {\n const { request, timestamp } = entry;\n const url = new URL(request.url);\n try {\n // Measurement protocol requests can set their payload parameters in\n // either the URL query string (for GET requests) or the POST body.\n const params = request.method === 'POST' ?\n new URLSearchParams(await request.clone().text()) :\n url.searchParams;\n // Calculate the qt param, accounting for the fact that an existing\n // qt param may be present and should be updated rather than replaced.\n const originalHitTime = timestamp - (Number(params.get('qt')) || 0);\n const queueTime = Date.now() - originalHitTime;\n // Set the qt param prior to applying hitFilter or parameterOverrides.\n params.set('qt', String(queueTime));\n // Apply `parameterOverrides`, if set.\n if (config.parameterOverrides) {\n for (const param of Object.keys(config.parameterOverrides)) {\n const value = config.parameterOverrides[param];\n params.set(param, value);\n }\n }\n // Apply `hitFilter`, if set.\n if (typeof config.hitFilter === 'function') {\n config.hitFilter.call(null, params);\n }\n // Retry the fetch. Ignore URL search params from the URL as they're\n // now in the post body.\n await fetch(new Request(url.origin + url.pathname, {\n body: params.toString(),\n method: 'POST',\n mode: 'cors',\n credentials: 'omit',\n headers: { 'Content-Type': 'text/plain' },\n }));\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(url.href)}'` +\n `has been replayed`);\n }\n }\n catch (err) {\n await queue.unshiftRequest(entry);\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(url.href)}'` +\n `failed to replay, putting it back in the queue.`);\n }\n throw err;\n }\n }\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`All Google Analytics request successfully replayed; ` +\n `the queue is now empty!`);\n }\n };\n};\n/**\n * Creates GET and POST routes to catch failed Measurement Protocol hits.\n *\n * @param {BackgroundSyncPlugin} bgSyncPlugin\n * @return {Array<Route>} The created routes.\n *\n * @private\n */\nconst createCollectRoutes = (bgSyncPlugin) => {\n const match = ({ url }) => url.hostname === GOOGLE_ANALYTICS_HOST &&\n COLLECT_PATHS_REGEX.test(url.pathname);\n const handler = new NetworkOnly({\n plugins: [bgSyncPlugin],\n });\n return [\n new Route(match, handler, 'GET'),\n new Route(match, handler, 'POST'),\n ];\n};\n/**\n * Creates a route with a network first strategy for the analytics.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createAnalyticsJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GOOGLE_ANALYTICS_HOST &&\n url.pathname === ANALYTICS_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * Creates a route with a network first strategy for the gtag.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createGtagJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GTM_HOST &&\n url.pathname === GTAG_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * Creates a route with a network first strategy for the gtm.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createGtmJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GTM_HOST &&\n url.pathname === GTM_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * @param {Object=} [options]\n * @param {Object} [options.cacheName] The cache name to store and retrieve\n * analytics.js. Defaults to the cache names provided by `workbox-core`.\n * @param {Object} [options.parameterOverrides]\n * [Measurement Protocol parameters](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters),\n * expressed as key/value pairs, to be added to replayed Google Analytics\n * requests. This can be used to, e.g., set a custom dimension indicating\n * that the request was replayed.\n * @param {Function} [options.hitFilter] A function that allows you to modify\n * the hit parameters prior to replaying\n * the hit. The function is invoked with the original hit's URLSearchParams\n * object as its only argument.\n *\n * @memberof module:workbox-google-analytics\n */\nconst initialize = (options = {}) => {\n const cacheName = cacheNames.getGoogleAnalyticsName(options.cacheName);\n const bgSyncPlugin = new BackgroundSyncPlugin(QUEUE_NAME, {\n maxRetentionTime: MAX_RETENTION_TIME,\n onSync: createOnSyncCallback(options),\n });\n const routes = [\n createGtmJsRoute(cacheName),\n createAnalyticsJsRoute(cacheName),\n createGtagJsRoute(cacheName),\n ...createCollectRoutes(bgSyncPlugin),\n ];\n const router = new Router();\n for (const route of routes) {\n router.registerRoute(route);\n }\n router.addFetchListener();\n};\nexport { initialize, };\n"],"names":["self","_","e","QUEUE_NAME","MAX_RETENTION_TIME","GOOGLE_ANALYTICS_HOST","GTM_HOST","ANALYTICS_JS_PATH","GTAG_JS_PATH","GTM_JS_PATH","COLLECT_PATHS_REGEX","createOnSyncCallback","config","queue","entry","shiftRequest","request","timestamp","url","URL","params","method","URLSearchParams","clone","text","searchParams","originalHitTime","Number","get","queueTime","Date","now","set","String","parameterOverrides","param","Object","keys","value","hitFilter","call","fetch","Request","origin","pathname","body","toString","mode","credentials","headers","process","logger","log","getFriendlyURL","href","err","unshiftRequest","createCollectRoutes","bgSyncPlugin","match","hostname","test","handler","NetworkOnly","plugins","Route","createAnalyticsJsRoute","cacheName","NetworkFirst","createGtagJsRoute","createGtmJsRoute","initialize","options","cacheNames","getGoogleAnalyticsName","BackgroundSyncPlugin","maxRetentionTime","onSync","routes","router","Router","route","registerRoute","addFetchListener"],"mappings":";;;;IAEA,IAAI;IACAA,EAAAA,IAAI,CAAC,gCAAD,CAAJ,IAA0CC,CAAC,EAA3C;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICLV;;;;;;;AAOA,IACO,MAAMC,UAAU,GAAG,0BAAnB;AACP,IAAO,MAAMC,kBAAkB,GAAG,KAAK,EAAhC;;AACP,IAAO,MAAMC,qBAAqB,GAAG,0BAA9B;AACP,IAAO,MAAMC,QAAQ,GAAG,0BAAjB;AACP,IAAO,MAAMC,iBAAiB,GAAG,eAA1B;AACP,IAAO,MAAMC,YAAY,GAAG,UAArB;AACP,IAAO,MAAMC,WAAW,GAAG,SAApB;AACP,IAEA;IACA;IACA;;AACA,IAAO,MAAMC,mBAAmB,GAAG,oBAA5B;;ICpBP;;;;;;;AAOA,IAUA;;;;;;;;;;;;IAWA,MAAMC,oBAAoB,GAAIC,MAAD,IAAY;IACrC,SAAO,OAAO;IAAEC,IAAAA;IAAF,GAAP,KAAqB;IACxB,QAAIC,KAAJ;;IACA,WAAOA,KAAK,GAAG,MAAMD,KAAK,CAACE,YAAN,EAArB,EAA2C;IACvC,YAAM;IAAEC,QAAAA,OAAF;IAAWC,QAAAA;IAAX,UAAyBH,KAA/B;IACA,YAAMI,GAAG,GAAG,IAAIC,GAAJ,CAAQH,OAAO,CAACE,GAAhB,CAAZ;;IACA,UAAI;IACA;IACA;IACA,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,CAAC6D,OAAD;IAF0B,GAArC,CAArB;IAIA,QAAMM,MAAM,GAAG,CACXR,gBAAgB,CAACH,SAAD,CADL,EAEXD,sBAAsB,CAACC,SAAD,CAFX,EAGXE,iBAAiB,CAACF,SAAD,CAHN,EAIX,GAAGV,mBAAmB,CAACC,YAAD,CAJX,CAAf;IAMA,QAAMqB,MAAM,GAAG,IAAIC,gBAAJ,EAAf;;IACA,OAAK,MAAMC,KAAX,IAAoBH,MAApB,EAA4B;IACxBC,IAAAA,MAAM,CAACG,aAAP,CAAqBD,KAArB;IACH;;IACDF,EAAAA,MAAM,CAACI,gBAAP;IACH,CAjBD;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- this.workbox=this.workbox||{},this.workbox.googleAnalytics=function(t,o,e,n,a,c,r,w,s){"use strict";try{self["workbox:google-analytics:5.1.1"]&&_()}catch(t){}const i=/^\/(\w+\/)?collect/,l=t=>{const o=({url:t})=>"www.google-analytics.com"===t.hostname&&i.test(t.pathname),e=new s.NetworkOnly({plugins:[t]});return[new c.Route(o,e,"GET"),new c.Route(o,e,"POST")]},g=t=>{const o=new w.NetworkFirst({cacheName:t});return new c.Route(({url:t})=>"www.google-analytics.com"===t.hostname&&"/analytics.js"===t.pathname,o,"GET")},m=t=>{const o=new w.NetworkFirst({cacheName:t});return new c.Route(({url:t})=>"www.googletagmanager.com"===t.hostname&&"/gtag/js"===t.pathname,o,"GET")},u=t=>{const o=new w.NetworkFirst({cacheName:t});return new c.Route(({url:t})=>"www.googletagmanager.com"===t.hostname&&"/gtm.js"===t.pathname,o,"GET")};return t.initialize=(t={})=>{const n=e.cacheNames.getGoogleAnalyticsName(t.cacheName),a=new o.BackgroundSyncPlugin("workbox-google-analytics",{maxRetentionTime:2880,onSync:(c=t,async({queue:t})=>{let o;for(;o=await t.shiftRequest();){const{request:e,timestamp:n}=o,a=new URL(e.url);try{const t="POST"===e.method?new URLSearchParams(await e.clone().text()):a.searchParams,o=n-(Number(t.get("qt"))||0),r=Date.now()-o;if(t.set("qt",String(r)),c.parameterOverrides)for(const o of Object.keys(c.parameterOverrides)){const e=c.parameterOverrides[o];t.set(o,e)}"function"==typeof c.hitFilter&&c.hitFilter.call(null,t),await fetch(new Request(a.origin+a.pathname,{body:t.toString(),method:"POST",mode:"cors",credentials:"omit",headers:{"Content-Type":"text/plain"}}))}catch(e){throw await t.unshiftRequest(o),e}}})});var c;const w=[u(n),g(n),m(n),...l(a)],s=new r.Router;for(const t of w)s.registerRoute(t);s.addFetchListener()},t}({},workbox.backgroundSync,workbox.core._private,workbox.core._private,workbox.core._private,workbox.routing,workbox.routing,workbox.strategies,workbox.strategies);
2
- //# sourceMappingURL=workbox-offline-ga.prod.js.map
1
+ this.workbox=this.workbox||{},this.workbox.googleAnalytics=function(t,o,e,n,a,c,r,w,s){"use strict";try{self["workbox:google-analytics:5.1.3"]&&_()}catch(t){}const i=/^\/(\w+\/)?collect/,l=t=>{const o=({url:t})=>"www.google-analytics.com"===t.hostname&&i.test(t.pathname),e=new s.NetworkOnly({plugins:[t]});return[new c.Route(o,e,"GET"),new c.Route(o,e,"POST")]},g=t=>{const o=new w.NetworkFirst({cacheName:t});return new c.Route(({url:t})=>"www.google-analytics.com"===t.hostname&&"/analytics.js"===t.pathname,o,"GET")},m=t=>{const o=new w.NetworkFirst({cacheName:t});return new c.Route(({url:t})=>"www.googletagmanager.com"===t.hostname&&"/gtag/js"===t.pathname,o,"GET")},u=t=>{const o=new w.NetworkFirst({cacheName:t});return new c.Route(({url:t})=>"www.googletagmanager.com"===t.hostname&&"/gtm.js"===t.pathname,o,"GET")};return t.initialize=(t={})=>{const n=e.cacheNames.getGoogleAnalyticsName(t.cacheName),a=new o.BackgroundSyncPlugin("workbox-google-analytics",{maxRetentionTime:2880,onSync:(c=t,async({queue:t})=>{let o;for(;o=await t.shiftRequest();){const{request:e,timestamp:n}=o,a=new URL(e.url);try{const t="POST"===e.method?new URLSearchParams(await e.clone().text()):a.searchParams,o=n-(Number(t.get("qt"))||0),r=Date.now()-o;if(t.set("qt",String(r)),c.parameterOverrides)for(const o of Object.keys(c.parameterOverrides)){const e=c.parameterOverrides[o];t.set(o,e)}"function"==typeof c.hitFilter&&c.hitFilter.call(null,t),await fetch(new Request(a.origin+a.pathname,{body:t.toString(),method:"POST",mode:"cors",credentials:"omit",headers:{"Content-Type":"text/plain"}}))}catch(e){throw await t.unshiftRequest(o),e}}})});var c;const w=[u(n),g(n),m(n),...l(a)],s=new r.Router;for(const t of w)s.registerRoute(t);s.addFetchListener()},t}({},workbox.backgroundSync,workbox.core._private,workbox.core._private,workbox.core._private,workbox.routing,workbox.routing,workbox.strategies,workbox.strategies);
2
+ //# sourceMappingURL=workbox-offline-ga.prod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"workbox-offline-ga.prod.js","sources":["../_version.js","../utils/constants.js","../initialize.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:google-analytics:5.1.1'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport '../_version.js';\nexport const QUEUE_NAME = 'workbox-google-analytics';\nexport const MAX_RETENTION_TIME = 60 * 48; // Two days in minutes\nexport const GOOGLE_ANALYTICS_HOST = 'www.google-analytics.com';\nexport const GTM_HOST = 'www.googletagmanager.com';\nexport const ANALYTICS_JS_PATH = '/analytics.js';\nexport const GTAG_JS_PATH = '/gtag/js';\nexport const GTM_JS_PATH = '/gtm.js';\nexport const COLLECT_DEFAULT_PATH = '/collect';\n// This RegExp matches all known Measurement Protocol single-hit collect\n// endpoints. Most of the time the default path (/collect) is used, but\n// occasionally an experimental endpoint is used when testing new features,\n// (e.g. /r/collect or /j/collect)\nexport const COLLECT_PATHS_REGEX = /^\\/(\\w+\\/)?collect/;\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { BackgroundSyncPlugin } from 'workbox-background-sync/BackgroundSyncPlugin.js';\nimport { cacheNames } from 'workbox-core/_private/cacheNames.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Route } from 'workbox-routing/Route.js';\nimport { Router } from 'workbox-routing/Router.js';\nimport { NetworkFirst } from 'workbox-strategies/NetworkFirst.js';\nimport { NetworkOnly } from 'workbox-strategies/NetworkOnly.js';\nimport { QUEUE_NAME, MAX_RETENTION_TIME, GOOGLE_ANALYTICS_HOST, GTM_HOST, ANALYTICS_JS_PATH, GTAG_JS_PATH, GTM_JS_PATH, COLLECT_PATHS_REGEX, } from './utils/constants.js';\nimport './_version.js';\n/**\n * Creates the requestWillDequeue callback to be used with the background\n * sync plugin. The callback takes the failed request and adds the\n * `qt` param based on the current time, as well as applies any other\n * user-defined hit modifications.\n *\n * @param {Object} config See {@link module:workbox-google-analytics.initialize}.\n * @return {Function} The requestWillDequeue callback function.\n *\n * @private\n */\nconst createOnSyncCallback = (config) => {\n return async ({ queue }) => {\n let entry;\n while (entry = await queue.shiftRequest()) {\n const { request, timestamp } = entry;\n const url = new URL(request.url);\n try {\n // Measurement protocol requests can set their payload parameters in\n // either the URL query string (for GET requests) or the POST body.\n const params = request.method === 'POST' ?\n new URLSearchParams(await request.clone().text()) :\n url.searchParams;\n // Calculate the qt param, accounting for the fact that an existing\n // qt param may be present and should be updated rather than replaced.\n const originalHitTime = timestamp - (Number(params.get('qt')) || 0);\n const queueTime = Date.now() - originalHitTime;\n // Set the qt param prior to applying hitFilter or parameterOverrides.\n params.set('qt', String(queueTime));\n // Apply `parameterOverrides`, if set.\n if (config.parameterOverrides) {\n for (const param of Object.keys(config.parameterOverrides)) {\n const value = config.parameterOverrides[param];\n params.set(param, value);\n }\n }\n // Apply `hitFilter`, if set.\n if (typeof config.hitFilter === 'function') {\n config.hitFilter.call(null, params);\n }\n // Retry the fetch. Ignore URL search params from the URL as they're\n // now in the post body.\n await fetch(new Request(url.origin + url.pathname, {\n body: params.toString(),\n method: 'POST',\n mode: 'cors',\n credentials: 'omit',\n headers: { 'Content-Type': 'text/plain' },\n }));\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(url.href)}'` +\n `has been replayed`);\n }\n }\n catch (err) {\n await queue.unshiftRequest(entry);\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(url.href)}'` +\n `failed to replay, putting it back in the queue.`);\n }\n throw err;\n }\n }\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`All Google Analytics request successfully replayed; ` +\n `the queue is now empty!`);\n }\n };\n};\n/**\n * Creates GET and POST routes to catch failed Measurement Protocol hits.\n *\n * @param {BackgroundSyncPlugin} bgSyncPlugin\n * @return {Array<Route>} The created routes.\n *\n * @private\n */\nconst createCollectRoutes = (bgSyncPlugin) => {\n const match = ({ url }) => url.hostname === GOOGLE_ANALYTICS_HOST &&\n COLLECT_PATHS_REGEX.test(url.pathname);\n const handler = new NetworkOnly({\n plugins: [bgSyncPlugin],\n });\n return [\n new Route(match, handler, 'GET'),\n new Route(match, handler, 'POST'),\n ];\n};\n/**\n * Creates a route with a network first strategy for the analytics.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createAnalyticsJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GOOGLE_ANALYTICS_HOST &&\n url.pathname === ANALYTICS_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * Creates a route with a network first strategy for the gtag.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createGtagJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GTM_HOST &&\n url.pathname === GTAG_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * Creates a route with a network first strategy for the gtm.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createGtmJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GTM_HOST &&\n url.pathname === GTM_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * @param {Object=} [options]\n * @param {Object} [options.cacheName] The cache name to store and retrieve\n * analytics.js. Defaults to the cache names provided by `workbox-core`.\n * @param {Object} [options.parameterOverrides]\n * [Measurement Protocol parameters](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters),\n * expressed as key/value pairs, to be added to replayed Google Analytics\n * requests. This can be used to, e.g., set a custom dimension indicating\n * that the request was replayed.\n * @param {Function} [options.hitFilter] A function that allows you to modify\n * the hit parameters prior to replaying\n * the hit. The function is invoked with the original hit's URLSearchParams\n * object as its only argument.\n *\n * @memberof module:workbox-google-analytics\n */\nconst initialize = (options = {}) => {\n const cacheName = cacheNames.getGoogleAnalyticsName(options.cacheName);\n const bgSyncPlugin = new BackgroundSyncPlugin(QUEUE_NAME, {\n maxRetentionTime: MAX_RETENTION_TIME,\n onSync: createOnSyncCallback(options),\n });\n const routes = [\n createGtmJsRoute(cacheName),\n createAnalyticsJsRoute(cacheName),\n createGtagJsRoute(cacheName),\n ...createCollectRoutes(bgSyncPlugin),\n ];\n const router = new Router();\n for (const route of routes) {\n router.registerRoute(route);\n }\n router.addFetchListener();\n};\nexport { initialize, };\n"],"names":["self","_","e","COLLECT_PATHS_REGEX","createCollectRoutes","bgSyncPlugin","match","url","hostname","test","pathname","handler","NetworkOnly","plugins","Route","createAnalyticsJsRoute","cacheName","NetworkFirst","createGtagJsRoute","createGtmJsRoute","options","cacheNames","getGoogleAnalyticsName","BackgroundSyncPlugin","maxRetentionTime","onSync","config","async","queue","entry","shiftRequest","request","timestamp","URL","params","method","URLSearchParams","clone","text","searchParams","originalHitTime","Number","get","queueTime","Date","now","set","String","parameterOverrides","param","Object","keys","value","hitFilter","call","fetch","Request","origin","body","toString","m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GAC3DC,EAAYC,KAAKC,MAAQL,KAE/BN,EAAOY,IAAI,KAAMC,OAAOJ,IAEpBjB,EAAOsB,uBACF,MAAMC,KAASC,OAAOC,KAAKzB,EAAOsB,oBAAqB,OAClDI,EAAQ1B,EAAOsB,mBAAmBC,GACxCf,EAAOY,IAAIG,EAAOG,GAIM,mBAArB1B,EAAO2B,WACd3B,EAAO2B,UAAUC,KAAK,KAAMpB,SAI1BqB,MAAM,IAAIC,QAAQjD,EAAIkD,OAASlD,EAAIG,SAAU,CAC/CgD,KAAMxB,EAAOyB,WACbxB,OAAQ,OACRyB,KAAM,OACNC,YAAa,OACbC,QAAS,gBAAkB,iBAOnC,MAAOC,eACGnC,EAAMoC,eAAenC,GAKrBkC,QAjDQrC,IAAAA,QA6IpBuC,EAAS,CACX9C,EAAiBH,GACjBD,EAAuBC,GACvBE,EAAkBF,MACfZ,EAAoBC,IAErB6D,EAAS,IAAIC,aACd,MAAMC,KAASH,EAChBC,EAAOG,cAAcD,GAEzBF,EAAOI"}
1
+ {"version":3,"file":"workbox-offline-ga.prod.js","sources":["../_version.js","../utils/constants.js","../initialize.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:google-analytics:5.1.3'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport '../_version.js';\nexport const QUEUE_NAME = 'workbox-google-analytics';\nexport const MAX_RETENTION_TIME = 60 * 48; // Two days in minutes\nexport const GOOGLE_ANALYTICS_HOST = 'www.google-analytics.com';\nexport const GTM_HOST = 'www.googletagmanager.com';\nexport const ANALYTICS_JS_PATH = '/analytics.js';\nexport const GTAG_JS_PATH = '/gtag/js';\nexport const GTM_JS_PATH = '/gtm.js';\nexport const COLLECT_DEFAULT_PATH = '/collect';\n// This RegExp matches all known Measurement Protocol single-hit collect\n// endpoints. Most of the time the default path (/collect) is used, but\n// occasionally an experimental endpoint is used when testing new features,\n// (e.g. /r/collect or /j/collect)\nexport const COLLECT_PATHS_REGEX = /^\\/(\\w+\\/)?collect/;\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { BackgroundSyncPlugin } from 'workbox-background-sync/BackgroundSyncPlugin.js';\nimport { cacheNames } from 'workbox-core/_private/cacheNames.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Route } from 'workbox-routing/Route.js';\nimport { Router } from 'workbox-routing/Router.js';\nimport { NetworkFirst } from 'workbox-strategies/NetworkFirst.js';\nimport { NetworkOnly } from 'workbox-strategies/NetworkOnly.js';\nimport { QUEUE_NAME, MAX_RETENTION_TIME, GOOGLE_ANALYTICS_HOST, GTM_HOST, ANALYTICS_JS_PATH, GTAG_JS_PATH, GTM_JS_PATH, COLLECT_PATHS_REGEX, } from './utils/constants.js';\nimport './_version.js';\n/**\n * Creates the requestWillDequeue callback to be used with the background\n * sync plugin. The callback takes the failed request and adds the\n * `qt` param based on the current time, as well as applies any other\n * user-defined hit modifications.\n *\n * @param {Object} config See {@link module:workbox-google-analytics.initialize}.\n * @return {Function} The requestWillDequeue callback function.\n *\n * @private\n */\nconst createOnSyncCallback = (config) => {\n return async ({ queue }) => {\n let entry;\n while (entry = await queue.shiftRequest()) {\n const { request, timestamp } = entry;\n const url = new URL(request.url);\n try {\n // Measurement protocol requests can set their payload parameters in\n // either the URL query string (for GET requests) or the POST body.\n const params = request.method === 'POST' ?\n new URLSearchParams(await request.clone().text()) :\n url.searchParams;\n // Calculate the qt param, accounting for the fact that an existing\n // qt param may be present and should be updated rather than replaced.\n const originalHitTime = timestamp - (Number(params.get('qt')) || 0);\n const queueTime = Date.now() - originalHitTime;\n // Set the qt param prior to applying hitFilter or parameterOverrides.\n params.set('qt', String(queueTime));\n // Apply `parameterOverrides`, if set.\n if (config.parameterOverrides) {\n for (const param of Object.keys(config.parameterOverrides)) {\n const value = config.parameterOverrides[param];\n params.set(param, value);\n }\n }\n // Apply `hitFilter`, if set.\n if (typeof config.hitFilter === 'function') {\n config.hitFilter.call(null, params);\n }\n // Retry the fetch. Ignore URL search params from the URL as they're\n // now in the post body.\n await fetch(new Request(url.origin + url.pathname, {\n body: params.toString(),\n method: 'POST',\n mode: 'cors',\n credentials: 'omit',\n headers: { 'Content-Type': 'text/plain' },\n }));\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(url.href)}'` +\n `has been replayed`);\n }\n }\n catch (err) {\n await queue.unshiftRequest(entry);\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(url.href)}'` +\n `failed to replay, putting it back in the queue.`);\n }\n throw err;\n }\n }\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`All Google Analytics request successfully replayed; ` +\n `the queue is now empty!`);\n }\n };\n};\n/**\n * Creates GET and POST routes to catch failed Measurement Protocol hits.\n *\n * @param {BackgroundSyncPlugin} bgSyncPlugin\n * @return {Array<Route>} The created routes.\n *\n * @private\n */\nconst createCollectRoutes = (bgSyncPlugin) => {\n const match = ({ url }) => url.hostname === GOOGLE_ANALYTICS_HOST &&\n COLLECT_PATHS_REGEX.test(url.pathname);\n const handler = new NetworkOnly({\n plugins: [bgSyncPlugin],\n });\n return [\n new Route(match, handler, 'GET'),\n new Route(match, handler, 'POST'),\n ];\n};\n/**\n * Creates a route with a network first strategy for the analytics.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createAnalyticsJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GOOGLE_ANALYTICS_HOST &&\n url.pathname === ANALYTICS_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * Creates a route with a network first strategy for the gtag.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createGtagJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GTM_HOST &&\n url.pathname === GTAG_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * Creates a route with a network first strategy for the gtm.js script.\n *\n * @param {string} cacheName\n * @return {Route} The created route.\n *\n * @private\n */\nconst createGtmJsRoute = (cacheName) => {\n const match = ({ url }) => url.hostname === GTM_HOST &&\n url.pathname === GTM_JS_PATH;\n const handler = new NetworkFirst({ cacheName });\n return new Route(match, handler, 'GET');\n};\n/**\n * @param {Object=} [options]\n * @param {Object} [options.cacheName] The cache name to store and retrieve\n * analytics.js. Defaults to the cache names provided by `workbox-core`.\n * @param {Object} [options.parameterOverrides]\n * [Measurement Protocol parameters](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters),\n * expressed as key/value pairs, to be added to replayed Google Analytics\n * requests. This can be used to, e.g., set a custom dimension indicating\n * that the request was replayed.\n * @param {Function} [options.hitFilter] A function that allows you to modify\n * the hit parameters prior to replaying\n * the hit. The function is invoked with the original hit's URLSearchParams\n * object as its only argument.\n *\n * @memberof module:workbox-google-analytics\n */\nconst initialize = (options = {}) => {\n const cacheName = cacheNames.getGoogleAnalyticsName(options.cacheName);\n const bgSyncPlugin = new BackgroundSyncPlugin(QUEUE_NAME, {\n maxRetentionTime: MAX_RETENTION_TIME,\n onSync: createOnSyncCallback(options),\n });\n const routes = [\n createGtmJsRoute(cacheName),\n createAnalyticsJsRoute(cacheName),\n createGtagJsRoute(cacheName),\n ...createCollectRoutes(bgSyncPlugin),\n ];\n const router = new Router();\n for (const route of routes) {\n router.registerRoute(route);\n }\n router.addFetchListener();\n};\nexport { initialize, };\n"],"names":["self","_","e","COLLECT_PATHS_REGEX","createCollectRoutes","bgSyncPlugin","match","url","hostname","test","pathname","handler","NetworkOnly","plugins","Route","createAnalyticsJsRoute","cacheName","NetworkFirst","createGtagJsRoute","createGtmJsRoute","options","cacheNames","getGoogleAnalyticsName","BackgroundSyncPlugin","maxRetentionTime","onSync","config","async","queue","entry","shiftRequest","request","timestamp","URL","params","method","URLSearchParams","clone","text","searchParams","originalHitTime","Number","get","queueTime","Date","now","set","String","parameterOverrides","param","Object","keys","value","hitFilter","call","fetch","Request","origin","body","toString","mode","credentials","headers","err","unshiftRequest","routes","router","Router","route","registerRoute","addFetchListener"],"mappings":"oGAEA,IACIA,KAAK,mCAAqCC,IAE9C,MAAOC,ICGA,MAYMC,EAAsB,qBC0E7BC,EAAuBC,UACnBC,EAAQ,EAAGC,IAAAA,KDrFgB,6BCqFNA,EAAIC,UAC3BL,EAAoBM,KAAKF,EAAIG,UAC3BC,EAAU,IAAIC,cAAY,CAC5BC,QAAS,CAACR,WAEP,CACH,IAAIS,QAAMR,EAAOK,EAAS,OAC1B,IAAIG,QAAMR,EAAOK,EAAS,UAW5BI,EAA0BC,UAGtBL,EAAU,IAAIM,eAAa,CAAED,UAAAA,WAC5B,IAAIF,QAHG,EAAGP,IAAAA,KDxGgB,6BCwGNA,EAAIC,UDtGF,kBCuGzBD,EAAIG,SAEgBC,EAAS,QAU/BO,EAAqBF,UAGjBL,EAAU,IAAIM,eAAa,CAAED,UAAAA,WAC5B,IAAIF,QAHG,EAAGP,IAAAA,KDrHG,6BCqHOA,EAAIC,UDnHP,aCoHpBD,EAAIG,SAEgBC,EAAS,QAU/BQ,EAAoBH,UAGhBL,EAAU,IAAIM,eAAa,CAAED,UAAAA,WAC5B,IAAIF,QAHG,EAAGP,IAAAA,KDnIG,6BCmIOA,EAAIC,UDhIR,YCiInBD,EAAIG,SAEgBC,EAAS,4BAkBlB,CAACS,EAAU,YACpBJ,EAAYK,aAAWC,uBAAuBF,EAAQJ,WACtDX,EAAe,IAAIkB,uBD7JH,2BC6JoC,CACtDC,iBD7J0B,KC8J1BC,QA3IsBC,EA2ION,EA1I1BO,OAASC,MAAAA,UACRC,OACGA,QAAcD,EAAME,gBAAgB,OACjCC,QAAEA,EAAFC,UAAWA,GAAcH,EACzBtB,EAAM,IAAI0B,IAAIF,EAAQxB,eAIlB2B,EAA4B,SAAnBH,EAAQI,OACnB,IAAIC,sBAAsBL,EAAQM,QAAQC,QAC1C/B,EAAIgC,aAGFC,EAAkBR,GAAaS,OAAOP,EAAOQ,IAAI,QAAU,GAC3DC,EAAYC,KAAKC,MAAQL,KAE/BN,EAAOY,IAAI,KAAMC,OAAOJ,IAEpBjB,EAAOsB,uBACF,MAAMC,KAASC,OAAOC,KAAKzB,EAAOsB,oBAAqB,OAClDI,EAAQ1B,EAAOsB,mBAAmBC,GACxCf,EAAOY,IAAIG,EAAOG,GAIM,mBAArB1B,EAAO2B,WACd3B,EAAO2B,UAAUC,KAAK,KAAMpB,SAI1BqB,MAAM,IAAIC,QAAQjD,EAAIkD,OAASlD,EAAIG,SAAU,CAC/CgD,KAAMxB,EAAOyB,WACbxB,OAAQ,OACRyB,KAAM,OACNC,YAAa,OACbC,QAAS,gBAAkB,iBAOnC,MAAOC,eACGnC,EAAMoC,eAAenC,GAKrBkC,QAjDQrC,IAAAA,QA6IpBuC,EAAS,CACX9C,EAAiBH,GACjBD,EAAuBC,GACvBE,EAAkBF,MACfZ,EAAoBC,IAErB6D,EAAS,IAAIC,aACd,MAAMC,KAASH,EAChBC,EAAOG,cAAcD,GAEzBF,EAAOI"}
@@ -1,1222 +1,1210 @@
1
- this.workbox = this.workbox || {};
2
- this.workbox.precaching = (function (exports, assert_js, cacheNames_js, getFriendlyURL_js, logger_js, cacheWrapper_js, fetchWrapper_js, WorkboxError_js, copyResponse_js) {
3
- 'use strict';
4
-
5
- try {
6
- self['workbox:precaching:5.1.1'] && _();
7
- } catch (e) {}
8
-
9
- /*
10
- Copyright 2019 Google LLC
11
-
12
- Use of this source code is governed by an MIT-style
13
- license that can be found in the LICENSE file or at
14
- https://opensource.org/licenses/MIT.
15
- */
16
- const plugins = [];
17
- const precachePlugins = {
18
- /*
19
- * @return {Array}
20
- * @private
21
- */
22
- get() {
23
- return plugins;
24
- },
25
-
26
- /*
27
- * @param {Array} newPlugins
28
- * @private
29
- */
30
- add(newPlugins) {
31
- plugins.push(...newPlugins);
32
- }
33
-
34
- };
35
-
36
- /*
37
- Copyright 2019 Google LLC
38
-
39
- Use of this source code is governed by an MIT-style
40
- license that can be found in the LICENSE file or at
41
- https://opensource.org/licenses/MIT.
42
- */
43
- /**
44
- * Adds plugins to precaching.
45
- *
46
- * @param {Array<Object>} newPlugins
47
- *
48
- * @memberof module:workbox-precaching
49
- */
50
-
51
- function addPlugins(newPlugins) {
52
- precachePlugins.add(newPlugins);
53
- }
54
-
55
- /*
56
- Copyright 2018 Google LLC
57
-
58
- Use of this source code is governed by an MIT-style
59
- license that can be found in the LICENSE file or at
60
- https://opensource.org/licenses/MIT.
61
- */
62
-
63
- const REVISION_SEARCH_PARAM = '__WB_REVISION__';
64
- /**
65
- * Converts a manifest entry into a versioned URL suitable for precaching.
66
- *
67
- * @param {Object|string} entry
68
- * @return {string} A URL with versioning info.
69
- *
70
- * @private
71
- * @memberof module:workbox-precaching
72
- */
73
-
74
- function createCacheKey(entry) {
75
- if (!entry) {
76
- throw new WorkboxError_js.WorkboxError('add-to-cache-list-unexpected-type', {
77
- entry
78
- });
79
- } // If a precache manifest entry is a string, it's assumed to be a versioned
80
- // URL, like '/app.abcd1234.js'. Return as-is.
81
-
82
-
83
- if (typeof entry === 'string') {
84
- const urlObject = new URL(entry, location.href);
85
- return {
86
- cacheKey: urlObject.href,
87
- url: urlObject.href
88
- };
89
- }
90
-
91
- const {
92
- revision,
93
- url
94
- } = entry;
95
-
96
- if (!url) {
97
- throw new WorkboxError_js.WorkboxError('add-to-cache-list-unexpected-type', {
98
- entry
99
- });
100
- } // If there's just a URL and no revision, then it's also assumed to be a
101
- // versioned URL.
102
-
103
-
104
- if (!revision) {
105
- const urlObject = new URL(url, location.href);
106
- return {
107
- cacheKey: urlObject.href,
108
- url: urlObject.href
109
- };
110
- } // Otherwise, construct a properly versioned URL using the custom Workbox
111
- // search parameter along with the revision info.
112
-
113
-
114
- const cacheKeyURL = new URL(url, location.href);
115
- const originalURL = new URL(url, location.href);
116
- cacheKeyURL.searchParams.set(REVISION_SEARCH_PARAM, revision);
117
- return {
118
- cacheKey: cacheKeyURL.href,
119
- url: originalURL.href
120
- };
121
- }
122
-
123
- /*
124
- Copyright 2018 Google LLC
125
-
126
- Use of this source code is governed by an MIT-style
127
- license that can be found in the LICENSE file or at
128
- https://opensource.org/licenses/MIT.
129
- */
130
- /**
131
- * @param {string} groupTitle
132
- * @param {Array<string>} deletedURLs
133
- *
134
- * @private
135
- */
136
-
137
- const logGroup = (groupTitle, deletedURLs) => {
138
- logger_js.logger.groupCollapsed(groupTitle);
139
-
140
- for (const url of deletedURLs) {
141
- logger_js.logger.log(url);
142
- }
143
-
144
- logger_js.logger.groupEnd();
145
- };
146
- /**
147
- * @param {Array<string>} deletedURLs
148
- *
149
- * @private
150
- * @memberof module:workbox-precaching
151
- */
152
-
153
-
154
- function printCleanupDetails(deletedURLs) {
155
- const deletionCount = deletedURLs.length;
156
-
157
- if (deletionCount > 0) {
158
- logger_js.logger.groupCollapsed(`During precaching cleanup, ` + `${deletionCount} cached ` + `request${deletionCount === 1 ? ' was' : 's were'} deleted.`);
159
- logGroup('Deleted Cache Requests', deletedURLs);
160
- logger_js.logger.groupEnd();
161
- }
162
- }
163
-
164
- /*
165
- Copyright 2018 Google LLC
166
-
167
- Use of this source code is governed by an MIT-style
168
- license that can be found in the LICENSE file or at
169
- https://opensource.org/licenses/MIT.
170
- */
171
- /**
172
- * @param {string} groupTitle
173
- * @param {Array<string>} urls
174
- *
175
- * @private
176
- */
177
-
178
- function _nestedGroup(groupTitle, urls) {
179
- if (urls.length === 0) {
180
- return;
181
- }
182
-
183
- logger_js.logger.groupCollapsed(groupTitle);
184
-
185
- for (const url of urls) {
186
- logger_js.logger.log(url);
187
- }
188
-
189
- logger_js.logger.groupEnd();
190
- }
191
- /**
192
- * @param {Array<string>} urlsToPrecache
193
- * @param {Array<string>} urlsAlreadyPrecached
194
- *
195
- * @private
196
- * @memberof module:workbox-precaching
197
- */
198
-
199
-
200
- function printInstallDetails(urlsToPrecache, urlsAlreadyPrecached) {
201
- const precachedCount = urlsToPrecache.length;
202
- const alreadyPrecachedCount = urlsAlreadyPrecached.length;
203
-
204
- if (precachedCount || alreadyPrecachedCount) {
205
- let message = `Precaching ${precachedCount} file${precachedCount === 1 ? '' : 's'}.`;
206
-
207
- if (alreadyPrecachedCount > 0) {
208
- message += ` ${alreadyPrecachedCount} ` + `file${alreadyPrecachedCount === 1 ? ' is' : 's are'} already cached.`;
209
- }
210
-
211
- logger_js.logger.groupCollapsed(message);
212
-
213
- _nestedGroup(`View newly precached URLs.`, urlsToPrecache);
214
-
215
- _nestedGroup(`View previously precached URLs.`, urlsAlreadyPrecached);
216
-
217
- logger_js.logger.groupEnd();
218
- }
219
- }
220
-
221
- /*
222
- Copyright 2019 Google LLC
223
-
224
- Use of this source code is governed by an MIT-style
225
- license that can be found in the LICENSE file or at
226
- https://opensource.org/licenses/MIT.
227
- */
228
- /**
229
- * Performs efficient precaching of assets.
230
- *
231
- * @memberof module:workbox-precaching
232
- */
233
-
234
- class PrecacheController {
235
- /**
236
- * Create a new PrecacheController.
237
- *
238
- * @param {string} [cacheName] An optional name for the cache, to override
239
- * the default precache name.
240
- */
241
- constructor(cacheName) {
242
- this._cacheName = cacheNames_js.cacheNames.getPrecacheName(cacheName);
243
- this._urlsToCacheKeys = new Map();
244
- this._urlsToCacheModes = new Map();
245
- this._cacheKeysToIntegrities = new Map();
246
- }
247
- /**
248
- * This method will add items to the precache list, removing duplicates
249
- * and ensuring the information is valid.
250
- *
251
- * @param {
252
- * Array<module:workbox-precaching.PrecacheController.PrecacheEntry|string>
253
- * } entries Array of entries to precache.
254
- */
255
-
256
-
257
- addToCacheList(entries) {
258
- {
259
- assert_js.assert.isArray(entries, {
260
- moduleName: 'workbox-precaching',
261
- className: 'PrecacheController',
262
- funcName: 'addToCacheList',
263
- paramName: 'entries'
264
- });
265
- }
266
-
267
- const urlsToWarnAbout = [];
268
-
269
- for (const entry of entries) {
270
- // See https://github.com/GoogleChrome/workbox/issues/2259
271
- if (typeof entry === 'string') {
272
- urlsToWarnAbout.push(entry);
273
- } else if (entry && entry.revision === undefined) {
274
- urlsToWarnAbout.push(entry.url);
275
- }
276
-
277
- const {
278
- cacheKey,
279
- url
280
- } = createCacheKey(entry);
281
- const cacheMode = typeof entry !== 'string' && entry.revision ? 'reload' : 'default';
282
-
283
- if (this._urlsToCacheKeys.has(url) && this._urlsToCacheKeys.get(url) !== cacheKey) {
284
- throw new WorkboxError_js.WorkboxError('add-to-cache-list-conflicting-entries', {
285
- firstEntry: this._urlsToCacheKeys.get(url),
286
- secondEntry: cacheKey
287
- });
288
- }
289
-
290
- if (typeof entry !== 'string' && entry.integrity) {
291
- if (this._cacheKeysToIntegrities.has(cacheKey) && this._cacheKeysToIntegrities.get(cacheKey) !== entry.integrity) {
292
- throw new WorkboxError_js.WorkboxError('add-to-cache-list-conflicting-integrities', {
293
- url
294
- });
295
- }
296
-
297
- this._cacheKeysToIntegrities.set(cacheKey, entry.integrity);
298
- }
299
-
300
- this._urlsToCacheKeys.set(url, cacheKey);
301
-
302
- this._urlsToCacheModes.set(url, cacheMode);
303
-
304
- if (urlsToWarnAbout.length > 0) {
305
- const warningMessage = `Workbox is precaching URLs without revision ` + `info: ${urlsToWarnAbout.join(', ')}\nThis is generally NOT safe. ` + `Learn more at https://bit.ly/wb-precache`;
306
-
307
- {
308
- logger_js.logger.warn(warningMessage);
309
- }
310
- }
311
- }
312
- }
313
- /**
314
- * Precaches new and updated assets. Call this method from the service worker
315
- * install event.
316
- *
317
- * @param {Object} options
318
- * @param {Event} [options.event] The install event (if needed).
319
- * @param {Array<Object>} [options.plugins] Plugins to be used for fetching
320
- * and caching during install.
321
- * @return {Promise<module:workbox-precaching.InstallResult>}
322
- */
323
-
324
-
325
- async install({
326
- event,
327
- plugins
328
- } = {}) {
329
- {
330
- if (plugins) {
331
- assert_js.assert.isArray(plugins, {
332
- moduleName: 'workbox-precaching',
333
- className: 'PrecacheController',
334
- funcName: 'install',
335
- paramName: 'plugins'
336
- });
337
- }
338
- }
339
-
340
- const toBePrecached = [];
341
- const alreadyPrecached = [];
342
- const cache = await self.caches.open(this._cacheName);
343
- const alreadyCachedRequests = await cache.keys();
344
- const existingCacheKeys = new Set(alreadyCachedRequests.map(request => request.url));
345
-
346
- for (const [url, cacheKey] of this._urlsToCacheKeys) {
347
- if (existingCacheKeys.has(cacheKey)) {
348
- alreadyPrecached.push(url);
349
- } else {
350
- toBePrecached.push({
351
- cacheKey,
352
- url
353
- });
354
- }
355
- }
356
-
357
- const precacheRequests = toBePrecached.map(({
358
- cacheKey,
359
- url
360
- }) => {
361
- const integrity = this._cacheKeysToIntegrities.get(cacheKey);
362
-
363
- const cacheMode = this._urlsToCacheModes.get(url);
364
-
365
- return this._addURLToCache({
366
- cacheKey,
367
- cacheMode,
368
- event,
369
- integrity,
370
- plugins,
371
- url
372
- });
373
- });
374
- await Promise.all(precacheRequests);
375
- const updatedURLs = toBePrecached.map(item => item.url);
376
-
377
- {
378
- printInstallDetails(updatedURLs, alreadyPrecached);
379
- }
380
-
381
- return {
382
- updatedURLs,
383
- notUpdatedURLs: alreadyPrecached
384
- };
385
- }
386
- /**
387
- * Deletes assets that are no longer present in the current precache manifest.
388
- * Call this method from the service worker activate event.
389
- *
390
- * @return {Promise<module:workbox-precaching.CleanupResult>}
391
- */
392
-
393
-
394
- async activate() {
395
- const cache = await self.caches.open(this._cacheName);
396
- const currentlyCachedRequests = await cache.keys();
397
- const expectedCacheKeys = new Set(this._urlsToCacheKeys.values());
398
- const deletedURLs = [];
399
-
400
- for (const request of currentlyCachedRequests) {
401
- if (!expectedCacheKeys.has(request.url)) {
402
- await cache.delete(request);
403
- deletedURLs.push(request.url);
404
- }
405
- }
406
-
407
- {
408
- printCleanupDetails(deletedURLs);
409
- }
410
-
411
- return {
412
- deletedURLs
413
- };
414
- }
415
- /**
416
- * Requests the entry and saves it to the cache if the response is valid.
417
- * By default, any response with a status code of less than 400 (including
418
- * opaque responses) is considered valid.
419
- *
420
- * If you need to use custom criteria to determine what's valid and what
421
- * isn't, then pass in an item in `options.plugins` that implements the
422
- * `cacheWillUpdate()` lifecycle event.
423
- *
424
- * @private
425
- * @param {Object} options
426
- * @param {string} options.cacheKey The string to use a cache key.
427
- * @param {string} options.url The URL to fetch and cache.
428
- * @param {string} [options.cacheMode] The cache mode for the network request.
429
- * @param {Event} [options.event] The install event (if passed).
430
- * @param {Array<Object>} [options.plugins] An array of plugins to apply to
431
- * fetch and caching.
432
- * @param {string} [options.integrity] The value to use for the `integrity`
433
- * field when making the request.
434
- */
435
-
436
-
437
- async _addURLToCache({
438
- cacheKey,
439
- url,
440
- cacheMode,
441
- event,
442
- plugins,
443
- integrity
444
- }) {
445
- const request = new Request(url, {
446
- integrity,
447
- cache: cacheMode,
448
- credentials: 'same-origin'
449
- });
450
- let response = await fetchWrapper_js.fetchWrapper.fetch({
451
- event,
452
- plugins,
453
- request
454
- }); // Allow developers to override the default logic about what is and isn't
455
- // valid by passing in a plugin implementing cacheWillUpdate(), e.g.
456
- // a `CacheableResponsePlugin` instance.
457
-
458
- let cacheWillUpdatePlugin;
459
-
460
- for (const plugin of plugins || []) {
461
- if ('cacheWillUpdate' in plugin) {
462
- cacheWillUpdatePlugin = plugin;
463
- }
464
- }
465
-
466
- const isValidResponse = cacheWillUpdatePlugin ? // Use a callback if provided. It returns a truthy value if valid.
467
- // NOTE: invoke the method on the plugin instance so the `this` context
468
- // is correct.
469
- await cacheWillUpdatePlugin.cacheWillUpdate({
470
- event,
471
- request,
472
- response
473
- }) : // Otherwise, default to considering any response status under 400 valid.
474
- // This includes, by default, considering opaque responses valid.
475
- response.status < 400; // Consider this a failure, leading to the `install` handler failing, if
476
- // we get back an invalid response.
477
-
478
- if (!isValidResponse) {
479
- throw new WorkboxError_js.WorkboxError('bad-precaching-response', {
480
- url,
481
- status: response.status
482
- });
483
- } // Redirected responses cannot be used to satisfy a navigation request, so
484
- // any redirected response must be "copied" rather than cloned, so the new
485
- // response doesn't contain the `redirected` flag. See:
486
- // https://bugs.chromium.org/p/chromium/issues/detail?id=669363&desc=2#c1
487
-
488
-
489
- if (response.redirected) {
490
- response = await copyResponse_js.copyResponse(response);
491
- }
492
-
493
- await cacheWrapper_js.cacheWrapper.put({
494
- event,
495
- plugins,
496
- response,
497
- // `request` already uses `url`. We may be able to reuse it.
498
- request: cacheKey === url ? request : new Request(cacheKey),
499
- cacheName: this._cacheName,
500
- matchOptions: {
501
- ignoreSearch: true
502
- }
503
- });
504
- }
505
- /**
506
- * Returns a mapping of a precached URL to the corresponding cache key, taking
507
- * into account the revision information for the URL.
508
- *
509
- * @return {Map<string, string>} A URL to cache key mapping.
510
- */
511
-
512
-
513
- getURLsToCacheKeys() {
514
- return this._urlsToCacheKeys;
515
- }
516
- /**
517
- * Returns a list of all the URLs that have been precached by the current
518
- * service worker.
519
- *
520
- * @return {Array<string>} The precached URLs.
521
- */
522
-
523
-
524
- getCachedURLs() {
525
- return [...this._urlsToCacheKeys.keys()];
526
- }
527
- /**
528
- * Returns the cache key used for storing a given URL. If that URL is
529
- * unversioned, like `/index.html', then the cache key will be the original
530
- * URL with a search parameter appended to it.
531
- *
532
- * @param {string} url A URL whose cache key you want to look up.
533
- * @return {string} The versioned URL that corresponds to a cache key
534
- * for the original URL, or undefined if that URL isn't precached.
535
- */
536
-
537
-
538
- getCacheKeyForURL(url) {
539
- const urlObject = new URL(url, location.href);
540
- return this._urlsToCacheKeys.get(urlObject.href);
541
- }
542
- /**
543
- * This acts as a drop-in replacement for [`cache.match()`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/match)
544
- * with the following differences:
545
- *
546
- * - It knows what the name of the precache is, and only checks in that cache.
547
- * - It allows you to pass in an "original" URL without versioning parameters,
548
- * and it will automatically look up the correct cache key for the currently
549
- * active revision of that URL.
550
- *
551
- * E.g., `matchPrecache('index.html')` will find the correct precached
552
- * response for the currently active service worker, even if the actual cache
553
- * key is `'/index.html?__WB_REVISION__=1234abcd'`.
554
- *
555
- * @param {string|Request} request The key (without revisioning parameters)
556
- * to look up in the precache.
557
- * @return {Promise<Response|undefined>}
558
- */
559
-
560
-
561
- async matchPrecache(request) {
562
- const url = request instanceof Request ? request.url : request;
563
- const cacheKey = this.getCacheKeyForURL(url);
564
-
565
- if (cacheKey) {
566
- const cache = await self.caches.open(this._cacheName);
567
- return cache.match(cacheKey);
568
- }
569
-
570
- return undefined;
571
- }
572
- /**
573
- * Returns a function that can be used within a
574
- * {@link module:workbox-routing.Route} that will find a response for the
575
- * incoming request against the precache.
576
- *
577
- * If for an unexpected reason there is a cache miss for the request,
578
- * this will fall back to retrieving the `Response` via `fetch()` when
579
- * `fallbackToNetwork` is `true`.
580
- *
581
- * @param {boolean} [fallbackToNetwork=true] Whether to attempt to get the
582
- * response from the network if there's a precache miss.
583
- * @return {module:workbox-routing~handlerCallback}
584
- */
585
-
586
-
587
- createHandler(fallbackToNetwork = true) {
588
- return async ({
589
- request
590
- }) => {
591
- try {
592
- const response = await this.matchPrecache(request);
593
-
594
- if (response) {
595
- return response;
596
- } // This shouldn't normally happen, but there are edge cases:
597
- // https://github.com/GoogleChrome/workbox/issues/1441
598
-
599
-
600
- throw new WorkboxError_js.WorkboxError('missing-precache-entry', {
601
- cacheName: this._cacheName,
602
- url: request instanceof Request ? request.url : request
603
- });
604
- } catch (error) {
605
- if (fallbackToNetwork) {
606
- {
607
- logger_js.logger.debug(`Unable to respond with precached response. ` + `Falling back to network.`, error);
608
- }
609
-
610
- return fetch(request);
611
- }
612
-
613
- throw error;
614
- }
615
- };
616
- }
617
- /**
618
- * Returns a function that looks up `url` in the precache (taking into
619
- * account revision information), and returns the corresponding `Response`.
620
- *
621
- * If for an unexpected reason there is a cache miss when looking up `url`,
622
- * this will fall back to retrieving the `Response` via `fetch()` when
623
- * `fallbackToNetwork` is `true`.
624
- *
625
- * @param {string} url The precached URL which will be used to lookup the
626
- * `Response`.
627
- * @param {boolean} [fallbackToNetwork=true] Whether to attempt to get the
628
- * response from the network if there's a precache miss.
629
- * @return {module:workbox-routing~handlerCallback}
630
- */
631
-
632
-
633
- createHandlerBoundToURL(url, fallbackToNetwork = true) {
634
- const cacheKey = this.getCacheKeyForURL(url);
635
-
636
- if (!cacheKey) {
637
- throw new WorkboxError_js.WorkboxError('non-precached-url', {
638
- url
639
- });
640
- }
641
-
642
- const handler = this.createHandler(fallbackToNetwork);
643
- const request = new Request(url);
644
- return () => handler({
645
- request
646
- });
647
- }
648
-
649
- }
650
-
651
- /*
652
- Copyright 2019 Google LLC
653
-
654
- Use of this source code is governed by an MIT-style
655
- license that can be found in the LICENSE file or at
656
- https://opensource.org/licenses/MIT.
657
- */
658
- let precacheController;
659
- /**
660
- * @return {PrecacheController}
661
- * @private
662
- */
663
-
664
- const getOrCreatePrecacheController = () => {
665
- if (!precacheController) {
666
- precacheController = new PrecacheController();
667
- }
668
-
669
- return precacheController;
670
- };
671
-
672
- /*
673
- Copyright 2018 Google LLC
674
-
675
- Use of this source code is governed by an MIT-style
676
- license that can be found in the LICENSE file or at
677
- https://opensource.org/licenses/MIT.
678
- */
679
- /**
680
- * Removes any URL search parameters that should be ignored.
681
- *
682
- * @param {URL} urlObject The original URL.
683
- * @param {Array<RegExp>} ignoreURLParametersMatching RegExps to test against
684
- * each search parameter name. Matches mean that the search parameter should be
685
- * ignored.
686
- * @return {URL} The URL with any ignored search parameters removed.
687
- *
688
- * @private
689
- * @memberof module:workbox-precaching
690
- */
691
-
692
- function removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching = []) {
693
- // Convert the iterable into an array at the start of the loop to make sure
694
- // deletion doesn't mess up iteration.
695
- for (const paramName of [...urlObject.searchParams.keys()]) {
696
- if (ignoreURLParametersMatching.some(regExp => regExp.test(paramName))) {
697
- urlObject.searchParams.delete(paramName);
698
- }
699
- }
700
-
701
- return urlObject;
702
- }
703
-
704
- /*
705
- Copyright 2019 Google LLC
706
-
707
- Use of this source code is governed by an MIT-style
708
- license that can be found in the LICENSE file or at
709
- https://opensource.org/licenses/MIT.
710
- */
711
- /**
712
- * Generator function that yields possible variations on the original URL to
713
- * check, one at a time.
714
- *
715
- * @param {string} url
716
- * @param {Object} options
717
- *
718
- * @private
719
- * @memberof module:workbox-precaching
720
- */
721
-
722
- function* generateURLVariations(url, {
723
- ignoreURLParametersMatching,
724
- directoryIndex,
725
- cleanURLs,
726
- urlManipulation
727
- } = {}) {
728
- const urlObject = new URL(url, location.href);
729
- urlObject.hash = '';
730
- yield urlObject.href;
731
- const urlWithoutIgnoredParams = removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching);
732
- yield urlWithoutIgnoredParams.href;
733
-
734
- if (directoryIndex && urlWithoutIgnoredParams.pathname.endsWith('/')) {
735
- const directoryURL = new URL(urlWithoutIgnoredParams.href);
736
- directoryURL.pathname += directoryIndex;
737
- yield directoryURL.href;
738
- }
739
-
740
- if (cleanURLs) {
741
- const cleanURL = new URL(urlWithoutIgnoredParams.href);
742
- cleanURL.pathname += '.html';
743
- yield cleanURL.href;
744
- }
745
-
746
- if (urlManipulation) {
747
- const additionalURLs = urlManipulation({
748
- url: urlObject
749
- });
750
-
751
- for (const urlToAttempt of additionalURLs) {
752
- yield urlToAttempt.href;
753
- }
754
- }
755
- }
756
-
757
- /*
758
- Copyright 2019 Google LLC
759
-
760
- Use of this source code is governed by an MIT-style
761
- license that can be found in the LICENSE file or at
762
- https://opensource.org/licenses/MIT.
763
- */
764
- /**
765
- * This function will take the request URL and manipulate it based on the
766
- * configuration options.
767
- *
768
- * @param {string} url
769
- * @param {Object} options
770
- * @return {string} Returns the URL in the cache that matches the request,
771
- * if possible.
772
- *
773
- * @private
774
- */
775
-
776
- const getCacheKeyForURL = (url, options) => {
777
- const precacheController = getOrCreatePrecacheController();
778
- const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
779
-
780
- for (const possibleURL of generateURLVariations(url, options)) {
781
- const possibleCacheKey = urlsToCacheKeys.get(possibleURL);
782
-
783
- if (possibleCacheKey) {
784
- return possibleCacheKey;
785
- }
786
- }
787
- };
788
-
789
- /*
790
- Copyright 2019 Google LLC
791
-
792
- Use of this source code is governed by an MIT-style
793
- license that can be found in the LICENSE file or at
794
- https://opensource.org/licenses/MIT.
795
- */
796
- /**
797
- * Adds a `fetch` listener to the service worker that will
798
- * respond to
799
- * [network requests]{@link https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#Custom_responses_to_requests}
800
- * with precached assets.
801
- *
802
- * Requests for assets that aren't precached, the `FetchEvent` will not be
803
- * responded to, allowing the event to fall through to other `fetch` event
804
- * listeners.
805
- *
806
- * NOTE: when called more than once this method will replace the previously set
807
- * configuration options. Calling it more than once is not recommended outside
808
- * of tests.
809
- *
810
- * @private
811
- * @param {Object} [options]
812
- * @param {string} [options.directoryIndex=index.html] The `directoryIndex` will
813
- * check cache entries for a URLs ending with '/' to see if there is a hit when
814
- * appending the `directoryIndex` value.
815
- * @param {Array<RegExp>} [options.ignoreURLParametersMatching=[/^utm_/]] An
816
- * array of regex's to remove search params when looking for a cache match.
817
- * @param {boolean} [options.cleanURLs=true] The `cleanURLs` option will
818
- * check the cache for the URL with a `.html` added to the end of the end.
819
- * @param {workbox.precaching~urlManipulation} [options.urlManipulation]
820
- * This is a function that should take a URL and return an array of
821
- * alternative URLs that should be checked for precache matches.
822
- */
823
-
824
- const addFetchListener = ({
825
- ignoreURLParametersMatching = [/^utm_/],
826
- directoryIndex = 'index.html',
827
- cleanURLs = true,
828
- urlManipulation
829
- } = {}) => {
830
- const cacheName = cacheNames_js.cacheNames.getPrecacheName(); // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
831
-
832
- self.addEventListener('fetch', event => {
833
- const precachedURL = getCacheKeyForURL(event.request.url, {
834
- cleanURLs,
835
- directoryIndex,
836
- ignoreURLParametersMatching,
837
- urlManipulation
838
- });
839
-
840
- if (!precachedURL) {
841
- {
842
- logger_js.logger.debug(`Precaching did not find a match for ` + getFriendlyURL_js.getFriendlyURL(event.request.url));
843
- }
844
-
845
- return;
846
- }
847
-
848
- let responsePromise = self.caches.open(cacheName).then(cache => {
849
- return cache.match(precachedURL);
850
- }).then(cachedResponse => {
851
- if (cachedResponse) {
852
- return cachedResponse;
853
- } // Fall back to the network if we don't have a cached response
854
- // (perhaps due to manual cache cleanup).
855
-
856
-
857
- {
858
- logger_js.logger.warn(`The precached response for ` + `${getFriendlyURL_js.getFriendlyURL(precachedURL)} in ${cacheName} was not found. ` + `Falling back to the network instead.`);
859
- }
860
-
861
- return fetch(precachedURL);
862
- });
863
-
864
- {
865
- responsePromise = responsePromise.then(response => {
866
- // Workbox is going to handle the route.
867
- // print the routing details to the console.
868
- logger_js.logger.groupCollapsed(`Precaching is responding to: ` + getFriendlyURL_js.getFriendlyURL(event.request.url));
869
- logger_js.logger.log(`Serving the precached url: ${precachedURL}`);
870
- logger_js.logger.groupCollapsed(`View request details here.`);
871
- logger_js.logger.log(event.request);
872
- logger_js.logger.groupEnd();
873
- logger_js.logger.groupCollapsed(`View response details here.`);
874
- logger_js.logger.log(response);
875
- logger_js.logger.groupEnd();
876
- logger_js.logger.groupEnd();
877
- return response;
878
- });
879
- }
880
-
881
- event.respondWith(responsePromise);
882
- });
883
- };
884
-
885
- /*
886
- Copyright 2019 Google LLC
887
- Use of this source code is governed by an MIT-style
888
- license that can be found in the LICENSE file or at
889
- https://opensource.org/licenses/MIT.
890
- */
891
- let listenerAdded = false;
892
- /**
893
- * Add a `fetch` listener to the service worker that will
894
- * respond to
895
- * [network requests]{@link https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#Custom_responses_to_requests}
896
- * with precached assets.
897
- *
898
- * Requests for assets that aren't precached, the `FetchEvent` will not be
899
- * responded to, allowing the event to fall through to other `fetch` event
900
- * listeners.
901
- *
902
- * @param {Object} [options]
903
- * @param {string} [options.directoryIndex=index.html] The `directoryIndex` will
904
- * check cache entries for a URLs ending with '/' to see if there is a hit when
905
- * appending the `directoryIndex` value.
906
- * @param {Array<RegExp>} [options.ignoreURLParametersMatching=[/^utm_/]] An
907
- * array of regex's to remove search params when looking for a cache match.
908
- * @param {boolean} [options.cleanURLs=true] The `cleanURLs` option will
909
- * check the cache for the URL with a `.html` added to the end of the end.
910
- * @param {module:workbox-precaching~urlManipulation} [options.urlManipulation]
911
- * This is a function that should take a URL and return an array of
912
- * alternative URLs that should be checked for precache matches.
913
- *
914
- * @memberof module:workbox-precaching
915
- */
916
-
917
- function addRoute(options) {
918
- if (!listenerAdded) {
919
- addFetchListener(options);
920
- listenerAdded = true;
921
- }
922
- }
923
-
924
- /*
925
- Copyright 2018 Google LLC
926
-
927
- Use of this source code is governed by an MIT-style
928
- license that can be found in the LICENSE file or at
929
- https://opensource.org/licenses/MIT.
930
- */
931
- const SUBSTRING_TO_FIND = '-precache-';
932
- /**
933
- * Cleans up incompatible precaches that were created by older versions of
934
- * Workbox, by a service worker registered under the current scope.
935
- *
936
- * This is meant to be called as part of the `activate` event.
937
- *
938
- * This should be safe to use as long as you don't include `substringToFind`
939
- * (defaulting to `-precache-`) in your non-precache cache names.
940
- *
941
- * @param {string} currentPrecacheName The cache name currently in use for
942
- * precaching. This cache won't be deleted.
943
- * @param {string} [substringToFind='-precache-'] Cache names which include this
944
- * substring will be deleted (excluding `currentPrecacheName`).
945
- * @return {Array<string>} A list of all the cache names that were deleted.
946
- *
947
- * @private
948
- * @memberof module:workbox-precaching
949
- */
950
-
951
- const deleteOutdatedCaches = async (currentPrecacheName, substringToFind = SUBSTRING_TO_FIND) => {
952
- const cacheNames = await self.caches.keys();
953
- const cacheNamesToDelete = cacheNames.filter(cacheName => {
954
- return cacheName.includes(substringToFind) && cacheName.includes(self.registration.scope) && cacheName !== currentPrecacheName;
955
- });
956
- await Promise.all(cacheNamesToDelete.map(cacheName => self.caches.delete(cacheName)));
957
- return cacheNamesToDelete;
958
- };
959
-
960
- /*
961
- Copyright 2019 Google LLC
962
-
963
- Use of this source code is governed by an MIT-style
964
- license that can be found in the LICENSE file or at
965
- https://opensource.org/licenses/MIT.
966
- */
967
- /**
968
- * Adds an `activate` event listener which will clean up incompatible
969
- * precaches that were created by older versions of Workbox.
970
- *
971
- * @memberof module:workbox-precaching
972
- */
973
-
974
- function cleanupOutdatedCaches() {
975
- // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
976
- self.addEventListener('activate', event => {
977
- const cacheName = cacheNames_js.cacheNames.getPrecacheName();
978
- event.waitUntil(deleteOutdatedCaches(cacheName).then(cachesDeleted => {
979
- {
980
- if (cachesDeleted.length > 0) {
981
- logger_js.logger.log(`The following out-of-date precaches were cleaned up ` + `automatically:`, cachesDeleted);
982
- }
983
- }
984
- }));
985
- });
986
- }
987
-
988
- /*
989
- Copyright 2019 Google LLC
990
-
991
- Use of this source code is governed by an MIT-style
992
- license that can be found in the LICENSE file or at
993
- https://opensource.org/licenses/MIT.
994
- */
995
- /**
996
- * Helper function that calls
997
- * {@link PrecacheController#createHandler} on the default
998
- * {@link PrecacheController} instance.
999
- *
1000
- * If you are creating your own {@link PrecacheController}, then call the
1001
- * {@link PrecacheController#createHandler} on that instance,
1002
- * instead of using this function.
1003
- *
1004
- * @param {boolean} [fallbackToNetwork=true] Whether to attempt to get the
1005
- * response from the network if there's a precache miss.
1006
- * @return {module:workbox-routing~handlerCallback}
1007
- *
1008
- * @memberof module:workbox-precaching
1009
- */
1010
-
1011
- function createHandler(fallbackToNetwork = true) {
1012
- const precacheController = getOrCreatePrecacheController();
1013
- return precacheController.createHandler(fallbackToNetwork);
1014
- }
1015
-
1016
- /*
1017
- Copyright 2019 Google LLC
1018
-
1019
- Use of this source code is governed by an MIT-style
1020
- license that can be found in the LICENSE file or at
1021
- https://opensource.org/licenses/MIT.
1022
- */
1023
- /**
1024
- * Helper function that calls
1025
- * {@link PrecacheController#createHandlerBoundToURL} on the default
1026
- * {@link PrecacheController} instance.
1027
- *
1028
- * If you are creating your own {@link PrecacheController}, then call the
1029
- * {@link PrecacheController#createHandlerBoundToURL} on that instance,
1030
- * instead of using this function.
1031
- *
1032
- * @param {string} url The precached URL which will be used to lookup the
1033
- * `Response`.
1034
- * @param {boolean} [fallbackToNetwork=true] Whether to attempt to get the
1035
- * response from the network if there's a precache miss.
1036
- * @return {module:workbox-routing~handlerCallback}
1037
- *
1038
- * @memberof module:workbox-precaching
1039
- */
1040
-
1041
- function createHandlerBoundToURL(url) {
1042
- const precacheController = getOrCreatePrecacheController();
1043
- return precacheController.createHandlerBoundToURL(url);
1044
- }
1045
-
1046
- /*
1047
- Copyright 2019 Google LLC
1048
-
1049
- Use of this source code is governed by an MIT-style
1050
- license that can be found in the LICENSE file or at
1051
- https://opensource.org/licenses/MIT.
1052
- */
1053
- /**
1054
- * Takes in a URL, and returns the corresponding URL that could be used to
1055
- * lookup the entry in the precache.
1056
- *
1057
- * If a relative URL is provided, the location of the service worker file will
1058
- * be used as the base.
1059
- *
1060
- * For precached entries without revision information, the cache key will be the
1061
- * same as the original URL.
1062
- *
1063
- * For precached entries with revision information, the cache key will be the
1064
- * original URL with the addition of a query parameter used for keeping track of
1065
- * the revision info.
1066
- *
1067
- * @param {string} url The URL whose cache key to look up.
1068
- * @return {string} The cache key that corresponds to that URL.
1069
- *
1070
- * @memberof module:workbox-precaching
1071
- */
1072
-
1073
- function getCacheKeyForURL$1(url) {
1074
- const precacheController = getOrCreatePrecacheController();
1075
- return precacheController.getCacheKeyForURL(url);
1076
- }
1077
-
1078
- /*
1079
- Copyright 2019 Google LLC
1080
-
1081
- Use of this source code is governed by an MIT-style
1082
- license that can be found in the LICENSE file or at
1083
- https://opensource.org/licenses/MIT.
1084
- */
1085
- /**
1086
- * Helper function that calls
1087
- * {@link PrecacheController#matchPrecache} on the default
1088
- * {@link PrecacheController} instance.
1089
- *
1090
- * If you are creating your own {@link PrecacheController}, then call
1091
- * {@link PrecacheController#matchPrecache} on that instance,
1092
- * instead of using this function.
1093
- *
1094
- * @param {string|Request} request The key (without revisioning parameters)
1095
- * to look up in the precache.
1096
- * @return {Promise<Response|undefined>}
1097
- *
1098
- * @memberof module:workbox-precaching
1099
- */
1100
-
1101
- function matchPrecache(request) {
1102
- const precacheController = getOrCreatePrecacheController();
1103
- return precacheController.matchPrecache(request);
1104
- }
1105
-
1106
- /*
1107
- Copyright 2019 Google LLC
1108
-
1109
- Use of this source code is governed by an MIT-style
1110
- license that can be found in the LICENSE file or at
1111
- https://opensource.org/licenses/MIT.
1112
- */
1113
-
1114
- const installListener = event => {
1115
- const precacheController = getOrCreatePrecacheController();
1116
- const plugins = precachePlugins.get();
1117
- event.waitUntil(precacheController.install({
1118
- event,
1119
- plugins
1120
- }).catch(error => {
1121
- {
1122
- logger_js.logger.error(`Service worker installation failed. It will ` + `be retried automatically during the next navigation.`);
1123
- } // Re-throw the error to ensure installation fails.
1124
-
1125
-
1126
- throw error;
1127
- }));
1128
- };
1129
-
1130
- const activateListener = event => {
1131
- const precacheController = getOrCreatePrecacheController();
1132
- event.waitUntil(precacheController.activate());
1133
- };
1134
- /**
1135
- * Adds items to the precache list, removing any duplicates and
1136
- * stores the files in the
1137
- * ["precache cache"]{@link module:workbox-core.cacheNames} when the service
1138
- * worker installs.
1139
- *
1140
- * This method can be called multiple times.
1141
- *
1142
- * Please note: This method **will not** serve any of the cached files for you.
1143
- * It only precaches files. To respond to a network request you call
1144
- * [addRoute()]{@link module:workbox-precaching.addRoute}.
1145
- *
1146
- * If you have a single array of files to precache, you can just call
1147
- * [precacheAndRoute()]{@link module:workbox-precaching.precacheAndRoute}.
1148
- *
1149
- * @param {Array<Object|string>} [entries=[]] Array of entries to precache.
1150
- *
1151
- * @memberof module:workbox-precaching
1152
- */
1153
-
1154
-
1155
- function precache(entries) {
1156
- const precacheController = getOrCreatePrecacheController();
1157
- precacheController.addToCacheList(entries);
1158
-
1159
- if (entries.length > 0) {
1160
- // NOTE: these listeners will only be added once (even if the `precache()`
1161
- // method is called multiple times) because event listeners are implemented
1162
- // as a set, where each listener must be unique.
1163
- // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
1164
- self.addEventListener('install', installListener);
1165
- self.addEventListener('activate', activateListener);
1166
- }
1167
- }
1168
-
1169
- /*
1170
- Copyright 2019 Google LLC
1171
-
1172
- Use of this source code is governed by an MIT-style
1173
- license that can be found in the LICENSE file or at
1174
- https://opensource.org/licenses/MIT.
1175
- */
1176
- /**
1177
- * This method will add entries to the precache list and add a route to
1178
- * respond to fetch events.
1179
- *
1180
- * This is a convenience method that will call
1181
- * [precache()]{@link module:workbox-precaching.precache} and
1182
- * [addRoute()]{@link module:workbox-precaching.addRoute} in a single call.
1183
- *
1184
- * @param {Array<Object|string>} entries Array of entries to precache.
1185
- * @param {Object} [options] See
1186
- * [addRoute() options]{@link module:workbox-precaching.addRoute}.
1187
- *
1188
- * @memberof module:workbox-precaching
1189
- */
1190
-
1191
- function precacheAndRoute(entries, options) {
1192
- precache(entries);
1193
- addRoute(options);
1194
- }
1195
-
1196
- /*
1197
- Copyright 2018 Google LLC
1198
-
1199
- Use of this source code is governed by an MIT-style
1200
- license that can be found in the LICENSE file or at
1201
- https://opensource.org/licenses/MIT.
1202
- */
1203
-
1204
- {
1205
- assert_js.assert.isSWEnv('workbox-precaching');
1206
- }
1207
-
1208
- exports.PrecacheController = PrecacheController;
1209
- exports.addPlugins = addPlugins;
1210
- exports.addRoute = addRoute;
1211
- exports.cleanupOutdatedCaches = cleanupOutdatedCaches;
1212
- exports.createHandler = createHandler;
1213
- exports.createHandlerBoundToURL = createHandlerBoundToURL;
1214
- exports.getCacheKeyForURL = getCacheKeyForURL$1;
1215
- exports.matchPrecache = matchPrecache;
1216
- exports.precache = precache;
1217
- exports.precacheAndRoute = precacheAndRoute;
1218
-
1219
- return exports;
1220
-
1221
- }({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core));
1222
- //# sourceMappingURL=workbox-precaching.dev.js.map
1
+ this.workbox = this.workbox || {};
2
+ this.workbox.precaching = (function (exports, cacheNames_js, getFriendlyURL_js, logger_js, assert_js, cacheWrapper_js, fetchWrapper_js, WorkboxError_js, copyResponse_js) {
3
+ 'use strict';
4
+
5
+ try {
6
+ self['workbox:precaching:5.1.3'] && _();
7
+ } catch (e) {}
8
+
9
+ /*
10
+ Copyright 2019 Google LLC
11
+
12
+ Use of this source code is governed by an MIT-style
13
+ license that can be found in the LICENSE file or at
14
+ https://opensource.org/licenses/MIT.
15
+ */
16
+ const plugins = [];
17
+ const precachePlugins = {
18
+ /*
19
+ * @return {Array}
20
+ * @private
21
+ */
22
+ get() {
23
+ return plugins;
24
+ },
25
+
26
+ /*
27
+ * @param {Array} newPlugins
28
+ * @private
29
+ */
30
+ add(newPlugins) {
31
+ plugins.push(...newPlugins);
32
+ }
33
+
34
+ };
35
+
36
+ /*
37
+ Copyright 2019 Google LLC
38
+
39
+ Use of this source code is governed by an MIT-style
40
+ license that can be found in the LICENSE file or at
41
+ https://opensource.org/licenses/MIT.
42
+ */
43
+ /**
44
+ * Adds plugins to precaching.
45
+ *
46
+ * @param {Array<Object>} newPlugins
47
+ *
48
+ * @memberof module:workbox-precaching
49
+ */
50
+
51
+ function addPlugins(newPlugins) {
52
+ precachePlugins.add(newPlugins);
53
+ }
54
+
55
+ /*
56
+ Copyright 2018 Google LLC
57
+
58
+ Use of this source code is governed by an MIT-style
59
+ license that can be found in the LICENSE file or at
60
+ https://opensource.org/licenses/MIT.
61
+ */
62
+
63
+ const REVISION_SEARCH_PARAM = '__WB_REVISION__';
64
+ /**
65
+ * Converts a manifest entry into a versioned URL suitable for precaching.
66
+ *
67
+ * @param {Object|string} entry
68
+ * @return {string} A URL with versioning info.
69
+ *
70
+ * @private
71
+ * @memberof module:workbox-precaching
72
+ */
73
+
74
+ function createCacheKey(entry) {
75
+ if (!entry) {
76
+ throw new WorkboxError_js.WorkboxError('add-to-cache-list-unexpected-type', {
77
+ entry
78
+ });
79
+ } // If a precache manifest entry is a string, it's assumed to be a versioned
80
+ // URL, like '/app.abcd1234.js'. Return as-is.
81
+
82
+
83
+ if (typeof entry === 'string') {
84
+ const urlObject = new URL(entry, location.href);
85
+ return {
86
+ cacheKey: urlObject.href,
87
+ url: urlObject.href
88
+ };
89
+ }
90
+
91
+ const {
92
+ revision,
93
+ url
94
+ } = entry;
95
+
96
+ if (!url) {
97
+ throw new WorkboxError_js.WorkboxError('add-to-cache-list-unexpected-type', {
98
+ entry
99
+ });
100
+ } // If there's just a URL and no revision, then it's also assumed to be a
101
+ // versioned URL.
102
+
103
+
104
+ if (!revision) {
105
+ const urlObject = new URL(url, location.href);
106
+ return {
107
+ cacheKey: urlObject.href,
108
+ url: urlObject.href
109
+ };
110
+ } // Otherwise, construct a properly versioned URL using the custom Workbox
111
+ // search parameter along with the revision info.
112
+
113
+
114
+ const cacheKeyURL = new URL(url, location.href);
115
+ const originalURL = new URL(url, location.href);
116
+ cacheKeyURL.searchParams.set(REVISION_SEARCH_PARAM, revision);
117
+ return {
118
+ cacheKey: cacheKeyURL.href,
119
+ url: originalURL.href
120
+ };
121
+ }
122
+
123
+ /*
124
+ Copyright 2018 Google LLC
125
+
126
+ Use of this source code is governed by an MIT-style
127
+ license that can be found in the LICENSE file or at
128
+ https://opensource.org/licenses/MIT.
129
+ */
130
+ /**
131
+ * @param {string} groupTitle
132
+ * @param {Array<string>} deletedURLs
133
+ *
134
+ * @private
135
+ */
136
+
137
+ const logGroup = (groupTitle, deletedURLs) => {
138
+ logger_js.logger.groupCollapsed(groupTitle);
139
+
140
+ for (const url of deletedURLs) {
141
+ logger_js.logger.log(url);
142
+ }
143
+
144
+ logger_js.logger.groupEnd();
145
+ };
146
+ /**
147
+ * @param {Array<string>} deletedURLs
148
+ *
149
+ * @private
150
+ * @memberof module:workbox-precaching
151
+ */
152
+
153
+
154
+ function printCleanupDetails(deletedURLs) {
155
+ const deletionCount = deletedURLs.length;
156
+
157
+ if (deletionCount > 0) {
158
+ logger_js.logger.groupCollapsed(`During precaching cleanup, ` + `${deletionCount} cached ` + `request${deletionCount === 1 ? ' was' : 's were'} deleted.`);
159
+ logGroup('Deleted Cache Requests', deletedURLs);
160
+ logger_js.logger.groupEnd();
161
+ }
162
+ }
163
+
164
+ /*
165
+ Copyright 2018 Google LLC
166
+
167
+ Use of this source code is governed by an MIT-style
168
+ license that can be found in the LICENSE file or at
169
+ https://opensource.org/licenses/MIT.
170
+ */
171
+ /**
172
+ * @param {string} groupTitle
173
+ * @param {Array<string>} urls
174
+ *
175
+ * @private
176
+ */
177
+
178
+ function _nestedGroup(groupTitle, urls) {
179
+ if (urls.length === 0) {
180
+ return;
181
+ }
182
+
183
+ logger_js.logger.groupCollapsed(groupTitle);
184
+
185
+ for (const url of urls) {
186
+ logger_js.logger.log(url);
187
+ }
188
+
189
+ logger_js.logger.groupEnd();
190
+ }
191
+ /**
192
+ * @param {Array<string>} urlsToPrecache
193
+ * @param {Array<string>} urlsAlreadyPrecached
194
+ *
195
+ * @private
196
+ * @memberof module:workbox-precaching
197
+ */
198
+
199
+
200
+ function printInstallDetails(urlsToPrecache, urlsAlreadyPrecached) {
201
+ const precachedCount = urlsToPrecache.length;
202
+ const alreadyPrecachedCount = urlsAlreadyPrecached.length;
203
+
204
+ if (precachedCount || alreadyPrecachedCount) {
205
+ let message = `Precaching ${precachedCount} file${precachedCount === 1 ? '' : 's'}.`;
206
+
207
+ if (alreadyPrecachedCount > 0) {
208
+ message += ` ${alreadyPrecachedCount} ` + `file${alreadyPrecachedCount === 1 ? ' is' : 's are'} already cached.`;
209
+ }
210
+
211
+ logger_js.logger.groupCollapsed(message);
212
+
213
+ _nestedGroup(`View newly precached URLs.`, urlsToPrecache);
214
+
215
+ _nestedGroup(`View previously precached URLs.`, urlsAlreadyPrecached);
216
+
217
+ logger_js.logger.groupEnd();
218
+ }
219
+ }
220
+
221
+ /*
222
+ Copyright 2019 Google LLC
223
+
224
+ Use of this source code is governed by an MIT-style
225
+ license that can be found in the LICENSE file or at
226
+ https://opensource.org/licenses/MIT.
227
+ */
228
+ /**
229
+ * Performs efficient precaching of assets.
230
+ *
231
+ * @memberof module:workbox-precaching
232
+ */
233
+
234
+ class PrecacheController {
235
+ /**
236
+ * Create a new PrecacheController.
237
+ *
238
+ * @param {string} [cacheName] An optional name for the cache, to override
239
+ * the default precache name.
240
+ */
241
+ constructor(cacheName) {
242
+ this._cacheName = cacheNames_js.cacheNames.getPrecacheName(cacheName);
243
+ this._urlsToCacheKeys = new Map();
244
+ this._urlsToCacheModes = new Map();
245
+ this._cacheKeysToIntegrities = new Map();
246
+ }
247
+ /**
248
+ * This method will add items to the precache list, removing duplicates
249
+ * and ensuring the information is valid.
250
+ *
251
+ * @param {
252
+ * Array<module:workbox-precaching.PrecacheController.PrecacheEntry|string>
253
+ * } entries Array of entries to precache.
254
+ */
255
+
256
+
257
+ addToCacheList(entries) {
258
+ {
259
+ assert_js.assert.isArray(entries, {
260
+ moduleName: 'workbox-precaching',
261
+ className: 'PrecacheController',
262
+ funcName: 'addToCacheList',
263
+ paramName: 'entries'
264
+ });
265
+ }
266
+
267
+ const urlsToWarnAbout = [];
268
+
269
+ for (const entry of entries) {
270
+ // See https://github.com/GoogleChrome/workbox/issues/2259
271
+ if (typeof entry === 'string') {
272
+ urlsToWarnAbout.push(entry);
273
+ } else if (entry && entry.revision === undefined) {
274
+ urlsToWarnAbout.push(entry.url);
275
+ }
276
+
277
+ const {
278
+ cacheKey,
279
+ url
280
+ } = createCacheKey(entry);
281
+ const cacheMode = typeof entry !== 'string' && entry.revision ? 'reload' : 'default';
282
+
283
+ if (this._urlsToCacheKeys.has(url) && this._urlsToCacheKeys.get(url) !== cacheKey) {
284
+ throw new WorkboxError_js.WorkboxError('add-to-cache-list-conflicting-entries', {
285
+ firstEntry: this._urlsToCacheKeys.get(url),
286
+ secondEntry: cacheKey
287
+ });
288
+ }
289
+
290
+ if (typeof entry !== 'string' && entry.integrity) {
291
+ if (this._cacheKeysToIntegrities.has(cacheKey) && this._cacheKeysToIntegrities.get(cacheKey) !== entry.integrity) {
292
+ throw new WorkboxError_js.WorkboxError('add-to-cache-list-conflicting-integrities', {
293
+ url
294
+ });
295
+ }
296
+
297
+ this._cacheKeysToIntegrities.set(cacheKey, entry.integrity);
298
+ }
299
+
300
+ this._urlsToCacheKeys.set(url, cacheKey);
301
+
302
+ this._urlsToCacheModes.set(url, cacheMode);
303
+
304
+ if (urlsToWarnAbout.length > 0) {
305
+ const warningMessage = `Workbox is precaching URLs without revision ` + `info: ${urlsToWarnAbout.join(', ')}\nThis is generally NOT safe. ` + `Learn more at https://bit.ly/wb-precache`;
306
+
307
+ {
308
+ logger_js.logger.warn(warningMessage);
309
+ }
310
+ }
311
+ }
312
+ }
313
+ /**
314
+ * Precaches new and updated assets. Call this method from the service worker
315
+ * install event.
316
+ *
317
+ * @param {Object} options
318
+ * @param {Event} [options.event] The install event (if needed).
319
+ * @param {Array<Object>} [options.plugins] Plugins to be used for fetching
320
+ * and caching during install.
321
+ * @return {Promise<module:workbox-precaching.InstallResult>}
322
+ */
323
+
324
+
325
+ async install({
326
+ event,
327
+ plugins
328
+ } = {}) {
329
+ {
330
+ if (plugins) {
331
+ assert_js.assert.isArray(plugins, {
332
+ moduleName: 'workbox-precaching',
333
+ className: 'PrecacheController',
334
+ funcName: 'install',
335
+ paramName: 'plugins'
336
+ });
337
+ }
338
+ }
339
+
340
+ const toBePrecached = [];
341
+ const alreadyPrecached = [];
342
+ const cache = await self.caches.open(this._cacheName);
343
+ const alreadyCachedRequests = await cache.keys();
344
+ const existingCacheKeys = new Set(alreadyCachedRequests.map(request => request.url));
345
+
346
+ for (const [url, cacheKey] of this._urlsToCacheKeys) {
347
+ if (existingCacheKeys.has(cacheKey)) {
348
+ alreadyPrecached.push(url);
349
+ } else {
350
+ toBePrecached.push({
351
+ cacheKey,
352
+ url
353
+ });
354
+ }
355
+ }
356
+
357
+ const precacheRequests = toBePrecached.map(({
358
+ cacheKey,
359
+ url
360
+ }) => {
361
+ const integrity = this._cacheKeysToIntegrities.get(cacheKey);
362
+
363
+ const cacheMode = this._urlsToCacheModes.get(url);
364
+
365
+ return this._addURLToCache({
366
+ cacheKey,
367
+ cacheMode,
368
+ event,
369
+ integrity,
370
+ plugins,
371
+ url
372
+ });
373
+ });
374
+ await Promise.all(precacheRequests);
375
+ const updatedURLs = toBePrecached.map(item => item.url);
376
+
377
+ {
378
+ printInstallDetails(updatedURLs, alreadyPrecached);
379
+ }
380
+
381
+ return {
382
+ updatedURLs,
383
+ notUpdatedURLs: alreadyPrecached
384
+ };
385
+ }
386
+ /**
387
+ * Deletes assets that are no longer present in the current precache manifest.
388
+ * Call this method from the service worker activate event.
389
+ *
390
+ * @return {Promise<module:workbox-precaching.CleanupResult>}
391
+ */
392
+
393
+
394
+ async activate() {
395
+ const cache = await self.caches.open(this._cacheName);
396
+ const currentlyCachedRequests = await cache.keys();
397
+ const expectedCacheKeys = new Set(this._urlsToCacheKeys.values());
398
+ const deletedURLs = [];
399
+
400
+ for (const request of currentlyCachedRequests) {
401
+ if (!expectedCacheKeys.has(request.url)) {
402
+ await cache.delete(request);
403
+ deletedURLs.push(request.url);
404
+ }
405
+ }
406
+
407
+ {
408
+ printCleanupDetails(deletedURLs);
409
+ }
410
+
411
+ return {
412
+ deletedURLs
413
+ };
414
+ }
415
+ /**
416
+ * Requests the entry and saves it to the cache if the response is valid.
417
+ * By default, any response with a status code of less than 400 (including
418
+ * opaque responses) is considered valid.
419
+ *
420
+ * If you need to use custom criteria to determine what's valid and what
421
+ * isn't, then pass in an item in `options.plugins` that implements the
422
+ * `cacheWillUpdate()` lifecycle event.
423
+ *
424
+ * @private
425
+ * @param {Object} options
426
+ * @param {string} options.cacheKey The string to use a cache key.
427
+ * @param {string} options.url The URL to fetch and cache.
428
+ * @param {string} [options.cacheMode] The cache mode for the network request.
429
+ * @param {Event} [options.event] The install event (if passed).
430
+ * @param {Array<Object>} [options.plugins] An array of plugins to apply to
431
+ * fetch and caching.
432
+ * @param {string} [options.integrity] The value to use for the `integrity`
433
+ * field when making the request.
434
+ */
435
+
436
+
437
+ async _addURLToCache({
438
+ cacheKey,
439
+ url,
440
+ cacheMode,
441
+ event,
442
+ plugins,
443
+ integrity
444
+ }) {
445
+ const request = new Request(url, {
446
+ integrity,
447
+ cache: cacheMode,
448
+ credentials: 'same-origin'
449
+ });
450
+ let response = await fetchWrapper_js.fetchWrapper.fetch({
451
+ event,
452
+ plugins,
453
+ request
454
+ }); // Allow developers to override the default logic about what is and isn't
455
+ // valid by passing in a plugin implementing cacheWillUpdate(), e.g.
456
+ // a `CacheableResponsePlugin` instance.
457
+
458
+ let cacheWillUpdatePlugin;
459
+
460
+ for (const plugin of plugins || []) {
461
+ if ('cacheWillUpdate' in plugin) {
462
+ cacheWillUpdatePlugin = plugin;
463
+ }
464
+ }
465
+
466
+ const isValidResponse = cacheWillUpdatePlugin ? // Use a callback if provided. It returns a truthy value if valid.
467
+ // NOTE: invoke the method on the plugin instance so the `this` context
468
+ // is correct.
469
+ await cacheWillUpdatePlugin.cacheWillUpdate({
470
+ event,
471
+ request,
472
+ response
473
+ }) : // Otherwise, default to considering any response status under 400 valid.
474
+ // This includes, by default, considering opaque responses valid.
475
+ response.status < 400; // Consider this a failure, leading to the `install` handler failing, if
476
+ // we get back an invalid response.
477
+
478
+ if (!isValidResponse) {
479
+ throw new WorkboxError_js.WorkboxError('bad-precaching-response', {
480
+ url,
481
+ status: response.status
482
+ });
483
+ } // Redirected responses cannot be used to satisfy a navigation request, so
484
+ // any redirected response must be "copied" rather than cloned, so the new
485
+ // response doesn't contain the `redirected` flag. See:
486
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=669363&desc=2#c1
487
+
488
+
489
+ if (response.redirected) {
490
+ response = await copyResponse_js.copyResponse(response);
491
+ }
492
+
493
+ await cacheWrapper_js.cacheWrapper.put({
494
+ event,
495
+ plugins,
496
+ response,
497
+ // `request` already uses `url`. We may be able to reuse it.
498
+ request: cacheKey === url ? request : new Request(cacheKey),
499
+ cacheName: this._cacheName,
500
+ matchOptions: {
501
+ ignoreSearch: true
502
+ }
503
+ });
504
+ }
505
+ /**
506
+ * Returns a mapping of a precached URL to the corresponding cache key, taking
507
+ * into account the revision information for the URL.
508
+ *
509
+ * @return {Map<string, string>} A URL to cache key mapping.
510
+ */
511
+
512
+
513
+ getURLsToCacheKeys() {
514
+ return this._urlsToCacheKeys;
515
+ }
516
+ /**
517
+ * Returns a list of all the URLs that have been precached by the current
518
+ * service worker.
519
+ *
520
+ * @return {Array<string>} The precached URLs.
521
+ */
522
+
523
+
524
+ getCachedURLs() {
525
+ return [...this._urlsToCacheKeys.keys()];
526
+ }
527
+ /**
528
+ * Returns the cache key used for storing a given URL. If that URL is
529
+ * unversioned, like `/index.html', then the cache key will be the original
530
+ * URL with a search parameter appended to it.
531
+ *
532
+ * @param {string} url A URL whose cache key you want to look up.
533
+ * @return {string} The versioned URL that corresponds to a cache key
534
+ * for the original URL, or undefined if that URL isn't precached.
535
+ */
536
+
537
+
538
+ getCacheKeyForURL(url) {
539
+ const urlObject = new URL(url, location.href);
540
+ return this._urlsToCacheKeys.get(urlObject.href);
541
+ }
542
+ /**
543
+ * This acts as a drop-in replacement for [`cache.match()`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/match)
544
+ * with the following differences:
545
+ *
546
+ * - It knows what the name of the precache is, and only checks in that cache.
547
+ * - It allows you to pass in an "original" URL without versioning parameters,
548
+ * and it will automatically look up the correct cache key for the currently
549
+ * active revision of that URL.
550
+ *
551
+ * E.g., `matchPrecache('index.html')` will find the correct precached
552
+ * response for the currently active service worker, even if the actual cache
553
+ * key is `'/index.html?__WB_REVISION__=1234abcd'`.
554
+ *
555
+ * @param {string|Request} request The key (without revisioning parameters)
556
+ * to look up in the precache.
557
+ * @return {Promise<Response|undefined>}
558
+ */
559
+
560
+
561
+ async matchPrecache(request) {
562
+ const url = request instanceof Request ? request.url : request;
563
+ const cacheKey = this.getCacheKeyForURL(url);
564
+
565
+ if (cacheKey) {
566
+ const cache = await self.caches.open(this._cacheName);
567
+ return cache.match(cacheKey);
568
+ }
569
+
570
+ return undefined;
571
+ }
572
+ /**
573
+ * Returns a function that can be used within a
574
+ * {@link module:workbox-routing.Route} that will find a response for the
575
+ * incoming request against the precache.
576
+ *
577
+ * If for an unexpected reason there is a cache miss for the request,
578
+ * this will fall back to retrieving the `Response` via `fetch()` when
579
+ * `fallbackToNetwork` is `true`.
580
+ *
581
+ * @param {boolean} [fallbackToNetwork=true] Whether to attempt to get the
582
+ * response from the network if there's a precache miss.
583
+ * @return {module:workbox-routing~handlerCallback}
584
+ */
585
+
586
+
587
+ createHandler(fallbackToNetwork = true) {
588
+ return async ({
589
+ request
590
+ }) => {
591
+ try {
592
+ const response = await this.matchPrecache(request);
593
+
594
+ if (response) {
595
+ return response;
596
+ } // This shouldn't normally happen, but there are edge cases:
597
+ // https://github.com/GoogleChrome/workbox/issues/1441
598
+
599
+
600
+ throw new WorkboxError_js.WorkboxError('missing-precache-entry', {
601
+ cacheName: this._cacheName,
602
+ url: request instanceof Request ? request.url : request
603
+ });
604
+ } catch (error) {
605
+ if (fallbackToNetwork) {
606
+ {
607
+ logger_js.logger.debug(`Unable to respond with precached response. ` + `Falling back to network.`, error);
608
+ }
609
+
610
+ return fetch(request);
611
+ }
612
+
613
+ throw error;
614
+ }
615
+ };
616
+ }
617
+ /**
618
+ * Returns a function that looks up `url` in the precache (taking into
619
+ * account revision information), and returns the corresponding `Response`.
620
+ *
621
+ * If for an unexpected reason there is a cache miss when looking up `url`,
622
+ * this will fall back to retrieving the `Response` via `fetch()` when
623
+ * `fallbackToNetwork` is `true`.
624
+ *
625
+ * @param {string} url The precached URL which will be used to lookup the
626
+ * `Response`.
627
+ * @param {boolean} [fallbackToNetwork=true] Whether to attempt to get the
628
+ * response from the network if there's a precache miss.
629
+ * @return {module:workbox-routing~handlerCallback}
630
+ */
631
+
632
+
633
+ createHandlerBoundToURL(url, fallbackToNetwork = true) {
634
+ const cacheKey = this.getCacheKeyForURL(url);
635
+
636
+ if (!cacheKey) {
637
+ throw new WorkboxError_js.WorkboxError('non-precached-url', {
638
+ url
639
+ });
640
+ }
641
+
642
+ const handler = this.createHandler(fallbackToNetwork);
643
+ const request = new Request(url);
644
+ return () => handler({
645
+ request
646
+ });
647
+ }
648
+
649
+ }
650
+
651
+ /*
652
+ Copyright 2019 Google LLC
653
+
654
+ Use of this source code is governed by an MIT-style
655
+ license that can be found in the LICENSE file or at
656
+ https://opensource.org/licenses/MIT.
657
+ */
658
+ let precacheController;
659
+ /**
660
+ * @return {PrecacheController}
661
+ * @private
662
+ */
663
+
664
+ const getOrCreatePrecacheController = () => {
665
+ if (!precacheController) {
666
+ precacheController = new PrecacheController();
667
+ }
668
+
669
+ return precacheController;
670
+ };
671
+
672
+ /*
673
+ Copyright 2018 Google LLC
674
+
675
+ Use of this source code is governed by an MIT-style
676
+ license that can be found in the LICENSE file or at
677
+ https://opensource.org/licenses/MIT.
678
+ */
679
+ /**
680
+ * Removes any URL search parameters that should be ignored.
681
+ *
682
+ * @param {URL} urlObject The original URL.
683
+ * @param {Array<RegExp>} ignoreURLParametersMatching RegExps to test against
684
+ * each search parameter name. Matches mean that the search parameter should be
685
+ * ignored.
686
+ * @return {URL} The URL with any ignored search parameters removed.
687
+ *
688
+ * @private
689
+ * @memberof module:workbox-precaching
690
+ */
691
+
692
+ function removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching = []) {
693
+ // Convert the iterable into an array at the start of the loop to make sure
694
+ // deletion doesn't mess up iteration.
695
+ for (const paramName of [...urlObject.searchParams.keys()]) {
696
+ if (ignoreURLParametersMatching.some(regExp => regExp.test(paramName))) {
697
+ urlObject.searchParams.delete(paramName);
698
+ }
699
+ }
700
+
701
+ return urlObject;
702
+ }
703
+
704
+ /*
705
+ Copyright 2019 Google LLC
706
+
707
+ Use of this source code is governed by an MIT-style
708
+ license that can be found in the LICENSE file or at
709
+ https://opensource.org/licenses/MIT.
710
+ */
711
+ /**
712
+ * Generator function that yields possible variations on the original URL to
713
+ * check, one at a time.
714
+ *
715
+ * @param {string} url
716
+ * @param {Object} options
717
+ *
718
+ * @private
719
+ * @memberof module:workbox-precaching
720
+ */
721
+
722
+ function* generateURLVariations(url, {
723
+ ignoreURLParametersMatching,
724
+ directoryIndex,
725
+ cleanURLs,
726
+ urlManipulation
727
+ } = {}) {
728
+ const urlObject = new URL(url, location.href);
729
+ urlObject.hash = '';
730
+ yield urlObject.href;
731
+ const urlWithoutIgnoredParams = removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching);
732
+ yield urlWithoutIgnoredParams.href;
733
+
734
+ if (directoryIndex && urlWithoutIgnoredParams.pathname.endsWith('/')) {
735
+ const directoryURL = new URL(urlWithoutIgnoredParams.href);
736
+ directoryURL.pathname += directoryIndex;
737
+ yield directoryURL.href;
738
+ }
739
+
740
+ if (cleanURLs) {
741
+ const cleanURL = new URL(urlWithoutIgnoredParams.href);
742
+ cleanURL.pathname += '.html';
743
+ yield cleanURL.href;
744
+ }
745
+
746
+ if (urlManipulation) {
747
+ const additionalURLs = urlManipulation({
748
+ url: urlObject
749
+ });
750
+
751
+ for (const urlToAttempt of additionalURLs) {
752
+ yield urlToAttempt.href;
753
+ }
754
+ }
755
+ }
756
+
757
+ /*
758
+ Copyright 2019 Google LLC
759
+
760
+ Use of this source code is governed by an MIT-style
761
+ license that can be found in the LICENSE file or at
762
+ https://opensource.org/licenses/MIT.
763
+ */
764
+ /**
765
+ * This function will take the request URL and manipulate it based on the
766
+ * configuration options.
767
+ *
768
+ * @param {string} url
769
+ * @param {Object} options
770
+ * @return {string} Returns the URL in the cache that matches the request,
771
+ * if possible.
772
+ *
773
+ * @private
774
+ */
775
+
776
+ const getCacheKeyForURL = (url, options) => {
777
+ const precacheController = getOrCreatePrecacheController();
778
+ const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
779
+
780
+ for (const possibleURL of generateURLVariations(url, options)) {
781
+ const possibleCacheKey = urlsToCacheKeys.get(possibleURL);
782
+
783
+ if (possibleCacheKey) {
784
+ return possibleCacheKey;
785
+ }
786
+ }
787
+ };
788
+
789
+ /*
790
+ Copyright 2019 Google LLC
791
+
792
+ Use of this source code is governed by an MIT-style
793
+ license that can be found in the LICENSE file or at
794
+ https://opensource.org/licenses/MIT.
795
+ */
796
+ /**
797
+ * Adds a `fetch` listener to the service worker that will
798
+ * respond to
799
+ * [network requests]{@link https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#Custom_responses_to_requests}
800
+ * with precached assets.
801
+ *
802
+ * Requests for assets that aren't precached, the `FetchEvent` will not be
803
+ * responded to, allowing the event to fall through to other `fetch` event
804
+ * listeners.
805
+ *
806
+ * NOTE: when called more than once this method will replace the previously set
807
+ * configuration options. Calling it more than once is not recommended outside
808
+ * of tests.
809
+ *
810
+ * @private
811
+ * @param {Object} [options]
812
+ * @param {string} [options.directoryIndex=index.html] The `directoryIndex` will
813
+ * check cache entries for a URLs ending with '/' to see if there is a hit when
814
+ * appending the `directoryIndex` value.
815
+ * @param {Array<RegExp>} [options.ignoreURLParametersMatching=[/^utm_/]] An
816
+ * array of regex's to remove search params when looking for a cache match.
817
+ * @param {boolean} [options.cleanURLs=true] The `cleanURLs` option will
818
+ * check the cache for the URL with a `.html` added to the end of the end.
819
+ * @param {workbox.precaching~urlManipulation} [options.urlManipulation]
820
+ * This is a function that should take a URL and return an array of
821
+ * alternative URLs that should be checked for precache matches.
822
+ */
823
+
824
+ const addFetchListener = ({
825
+ ignoreURLParametersMatching = [/^utm_/],
826
+ directoryIndex = 'index.html',
827
+ cleanURLs = true,
828
+ urlManipulation
829
+ } = {}) => {
830
+ const cacheName = cacheNames_js.cacheNames.getPrecacheName(); // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
831
+
832
+ self.addEventListener('fetch', event => {
833
+ const precachedURL = getCacheKeyForURL(event.request.url, {
834
+ cleanURLs,
835
+ directoryIndex,
836
+ ignoreURLParametersMatching,
837
+ urlManipulation
838
+ });
839
+
840
+ if (!precachedURL) {
841
+ {
842
+ logger_js.logger.debug(`Precaching did not find a match for ` + getFriendlyURL_js.getFriendlyURL(event.request.url));
843
+ }
844
+
845
+ return;
846
+ }
847
+
848
+ let responsePromise = self.caches.open(cacheName).then(cache => {
849
+ return cache.match(precachedURL);
850
+ }).then(cachedResponse => {
851
+ if (cachedResponse) {
852
+ return cachedResponse;
853
+ } // Fall back to the network if we don't have a cached response
854
+ // (perhaps due to manual cache cleanup).
855
+
856
+
857
+ {
858
+ logger_js.logger.warn(`The precached response for ` + `${getFriendlyURL_js.getFriendlyURL(precachedURL)} in ${cacheName} was not found. ` + `Falling back to the network instead.`);
859
+ }
860
+
861
+ return fetch(precachedURL);
862
+ });
863
+
864
+ {
865
+ responsePromise = responsePromise.then(response => {
866
+ // Workbox is going to handle the route.
867
+ // print the routing details to the console.
868
+ logger_js.logger.groupCollapsed(`Precaching is responding to: ` + getFriendlyURL_js.getFriendlyURL(event.request.url));
869
+ logger_js.logger.log(`Serving the precached url: ${precachedURL}`);
870
+ logger_js.logger.groupCollapsed(`View request details here.`);
871
+ logger_js.logger.log(event.request);
872
+ logger_js.logger.groupEnd();
873
+ logger_js.logger.groupCollapsed(`View response details here.`);
874
+ logger_js.logger.log(response);
875
+ logger_js.logger.groupEnd();
876
+ logger_js.logger.groupEnd();
877
+ return response;
878
+ });
879
+ }
880
+
881
+ event.respondWith(responsePromise);
882
+ });
883
+ };
884
+
885
+ /*
886
+ Copyright 2019 Google LLC
887
+ Use of this source code is governed by an MIT-style
888
+ license that can be found in the LICENSE file or at
889
+ https://opensource.org/licenses/MIT.
890
+ */
891
+ let listenerAdded = false;
892
+ /**
893
+ * Add a `fetch` listener to the service worker that will
894
+ * respond to
895
+ * [network requests]{@link https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#Custom_responses_to_requests}
896
+ * with precached assets.
897
+ *
898
+ * Requests for assets that aren't precached, the `FetchEvent` will not be
899
+ * responded to, allowing the event to fall through to other `fetch` event
900
+ * listeners.
901
+ *
902
+ * @param {Object} [options]
903
+ * @param {string} [options.directoryIndex=index.html] The `directoryIndex` will
904
+ * check cache entries for a URLs ending with '/' to see if there is a hit when
905
+ * appending the `directoryIndex` value.
906
+ * @param {Array<RegExp>} [options.ignoreURLParametersMatching=[/^utm_/]] An
907
+ * array of regex's to remove search params when looking for a cache match.
908
+ * @param {boolean} [options.cleanURLs=true] The `cleanURLs` option will
909
+ * check the cache for the URL with a `.html` added to the end of the end.
910
+ * @param {module:workbox-precaching~urlManipulation} [options.urlManipulation]
911
+ * This is a function that should take a URL and return an array of
912
+ * alternative URLs that should be checked for precache matches.
913
+ *
914
+ * @memberof module:workbox-precaching
915
+ */
916
+
917
+ function addRoute(options) {
918
+ if (!listenerAdded) {
919
+ addFetchListener(options);
920
+ listenerAdded = true;
921
+ }
922
+ }
923
+
924
+ /*
925
+ Copyright 2018 Google LLC
926
+
927
+ Use of this source code is governed by an MIT-style
928
+ license that can be found in the LICENSE file or at
929
+ https://opensource.org/licenses/MIT.
930
+ */
931
+ const SUBSTRING_TO_FIND = '-precache-';
932
+ /**
933
+ * Cleans up incompatible precaches that were created by older versions of
934
+ * Workbox, by a service worker registered under the current scope.
935
+ *
936
+ * This is meant to be called as part of the `activate` event.
937
+ *
938
+ * This should be safe to use as long as you don't include `substringToFind`
939
+ * (defaulting to `-precache-`) in your non-precache cache names.
940
+ *
941
+ * @param {string} currentPrecacheName The cache name currently in use for
942
+ * precaching. This cache won't be deleted.
943
+ * @param {string} [substringToFind='-precache-'] Cache names which include this
944
+ * substring will be deleted (excluding `currentPrecacheName`).
945
+ * @return {Array<string>} A list of all the cache names that were deleted.
946
+ *
947
+ * @private
948
+ * @memberof module:workbox-precaching
949
+ */
950
+
951
+ const deleteOutdatedCaches = async (currentPrecacheName, substringToFind = SUBSTRING_TO_FIND) => {
952
+ const cacheNames = await self.caches.keys();
953
+ const cacheNamesToDelete = cacheNames.filter(cacheName => {
954
+ return cacheName.includes(substringToFind) && cacheName.includes(self.registration.scope) && cacheName !== currentPrecacheName;
955
+ });
956
+ await Promise.all(cacheNamesToDelete.map(cacheName => self.caches.delete(cacheName)));
957
+ return cacheNamesToDelete;
958
+ };
959
+
960
+ /*
961
+ Copyright 2019 Google LLC
962
+
963
+ Use of this source code is governed by an MIT-style
964
+ license that can be found in the LICENSE file or at
965
+ https://opensource.org/licenses/MIT.
966
+ */
967
+ /**
968
+ * Adds an `activate` event listener which will clean up incompatible
969
+ * precaches that were created by older versions of Workbox.
970
+ *
971
+ * @memberof module:workbox-precaching
972
+ */
973
+
974
+ function cleanupOutdatedCaches() {
975
+ // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
976
+ self.addEventListener('activate', event => {
977
+ const cacheName = cacheNames_js.cacheNames.getPrecacheName();
978
+ event.waitUntil(deleteOutdatedCaches(cacheName).then(cachesDeleted => {
979
+ {
980
+ if (cachesDeleted.length > 0) {
981
+ logger_js.logger.log(`The following out-of-date precaches were cleaned up ` + `automatically:`, cachesDeleted);
982
+ }
983
+ }
984
+ }));
985
+ });
986
+ }
987
+
988
+ /*
989
+ Copyright 2019 Google LLC
990
+
991
+ Use of this source code is governed by an MIT-style
992
+ license that can be found in the LICENSE file or at
993
+ https://opensource.org/licenses/MIT.
994
+ */
995
+ /**
996
+ * Helper function that calls
997
+ * {@link PrecacheController#createHandler} on the default
998
+ * {@link PrecacheController} instance.
999
+ *
1000
+ * If you are creating your own {@link PrecacheController}, then call the
1001
+ * {@link PrecacheController#createHandler} on that instance,
1002
+ * instead of using this function.
1003
+ *
1004
+ * @param {boolean} [fallbackToNetwork=true] Whether to attempt to get the
1005
+ * response from the network if there's a precache miss.
1006
+ * @return {module:workbox-routing~handlerCallback}
1007
+ *
1008
+ * @memberof module:workbox-precaching
1009
+ */
1010
+
1011
+ function createHandler(fallbackToNetwork = true) {
1012
+ const precacheController = getOrCreatePrecacheController();
1013
+ return precacheController.createHandler(fallbackToNetwork);
1014
+ }
1015
+
1016
+ /*
1017
+ Copyright 2019 Google LLC
1018
+
1019
+ Use of this source code is governed by an MIT-style
1020
+ license that can be found in the LICENSE file or at
1021
+ https://opensource.org/licenses/MIT.
1022
+ */
1023
+ /**
1024
+ * Helper function that calls
1025
+ * {@link PrecacheController#createHandlerBoundToURL} on the default
1026
+ * {@link PrecacheController} instance.
1027
+ *
1028
+ * If you are creating your own {@link PrecacheController}, then call the
1029
+ * {@link PrecacheController#createHandlerBoundToURL} on that instance,
1030
+ * instead of using this function.
1031
+ *
1032
+ * @param {string} url The precached URL which will be used to lookup the
1033
+ * `Response`.
1034
+ * @param {boolean} [fallbackToNetwork=true] Whether to attempt to get the
1035
+ * response from the network if there's a precache miss.
1036
+ * @return {module:workbox-routing~handlerCallback}
1037
+ *
1038
+ * @memberof module:workbox-precaching
1039
+ */
1040
+
1041
+ function createHandlerBoundToURL(url) {
1042
+ const precacheController = getOrCreatePrecacheController();
1043
+ return precacheController.createHandlerBoundToURL(url);
1044
+ }
1045
+
1046
+ /*
1047
+ Copyright 2019 Google LLC
1048
+
1049
+ Use of this source code is governed by an MIT-style
1050
+ license that can be found in the LICENSE file or at
1051
+ https://opensource.org/licenses/MIT.
1052
+ */
1053
+ /**
1054
+ * Takes in a URL, and returns the corresponding URL that could be used to
1055
+ * lookup the entry in the precache.
1056
+ *
1057
+ * If a relative URL is provided, the location of the service worker file will
1058
+ * be used as the base.
1059
+ *
1060
+ * For precached entries without revision information, the cache key will be the
1061
+ * same as the original URL.
1062
+ *
1063
+ * For precached entries with revision information, the cache key will be the
1064
+ * original URL with the addition of a query parameter used for keeping track of
1065
+ * the revision info.
1066
+ *
1067
+ * @param {string} url The URL whose cache key to look up.
1068
+ * @return {string} The cache key that corresponds to that URL.
1069
+ *
1070
+ * @memberof module:workbox-precaching
1071
+ */
1072
+
1073
+ function getCacheKeyForURL$1(url) {
1074
+ const precacheController = getOrCreatePrecacheController();
1075
+ return precacheController.getCacheKeyForURL(url);
1076
+ }
1077
+
1078
+ /*
1079
+ Copyright 2019 Google LLC
1080
+
1081
+ Use of this source code is governed by an MIT-style
1082
+ license that can be found in the LICENSE file or at
1083
+ https://opensource.org/licenses/MIT.
1084
+ */
1085
+ /**
1086
+ * Helper function that calls
1087
+ * {@link PrecacheController#matchPrecache} on the default
1088
+ * {@link PrecacheController} instance.
1089
+ *
1090
+ * If you are creating your own {@link PrecacheController}, then call
1091
+ * {@link PrecacheController#matchPrecache} on that instance,
1092
+ * instead of using this function.
1093
+ *
1094
+ * @param {string|Request} request The key (without revisioning parameters)
1095
+ * to look up in the precache.
1096
+ * @return {Promise<Response|undefined>}
1097
+ *
1098
+ * @memberof module:workbox-precaching
1099
+ */
1100
+
1101
+ function matchPrecache(request) {
1102
+ const precacheController = getOrCreatePrecacheController();
1103
+ return precacheController.matchPrecache(request);
1104
+ }
1105
+
1106
+ /*
1107
+ Copyright 2019 Google LLC
1108
+
1109
+ Use of this source code is governed by an MIT-style
1110
+ license that can be found in the LICENSE file or at
1111
+ https://opensource.org/licenses/MIT.
1112
+ */
1113
+
1114
+ const installListener = event => {
1115
+ const precacheController = getOrCreatePrecacheController();
1116
+ const plugins = precachePlugins.get();
1117
+ event.waitUntil(precacheController.install({
1118
+ event,
1119
+ plugins
1120
+ }).catch(error => {
1121
+ {
1122
+ logger_js.logger.error(`Service worker installation failed. It will ` + `be retried automatically during the next navigation.`);
1123
+ } // Re-throw the error to ensure installation fails.
1124
+
1125
+
1126
+ throw error;
1127
+ }));
1128
+ };
1129
+
1130
+ const activateListener = event => {
1131
+ const precacheController = getOrCreatePrecacheController();
1132
+ event.waitUntil(precacheController.activate());
1133
+ };
1134
+ /**
1135
+ * Adds items to the precache list, removing any duplicates and
1136
+ * stores the files in the
1137
+ * ["precache cache"]{@link module:workbox-core.cacheNames} when the service
1138
+ * worker installs.
1139
+ *
1140
+ * This method can be called multiple times.
1141
+ *
1142
+ * Please note: This method **will not** serve any of the cached files for you.
1143
+ * It only precaches files. To respond to a network request you call
1144
+ * [addRoute()]{@link module:workbox-precaching.addRoute}.
1145
+ *
1146
+ * If you have a single array of files to precache, you can just call
1147
+ * [precacheAndRoute()]{@link module:workbox-precaching.precacheAndRoute}.
1148
+ *
1149
+ * @param {Array<Object|string>} [entries=[]] Array of entries to precache.
1150
+ *
1151
+ * @memberof module:workbox-precaching
1152
+ */
1153
+
1154
+
1155
+ function precache(entries) {
1156
+ const precacheController = getOrCreatePrecacheController();
1157
+ precacheController.addToCacheList(entries);
1158
+
1159
+ if (entries.length > 0) {
1160
+ // NOTE: these listeners will only be added once (even if the `precache()`
1161
+ // method is called multiple times) because event listeners are implemented
1162
+ // as a set, where each listener must be unique.
1163
+ // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
1164
+ self.addEventListener('install', installListener);
1165
+ self.addEventListener('activate', activateListener);
1166
+ }
1167
+ }
1168
+
1169
+ /*
1170
+ Copyright 2019 Google LLC
1171
+
1172
+ Use of this source code is governed by an MIT-style
1173
+ license that can be found in the LICENSE file or at
1174
+ https://opensource.org/licenses/MIT.
1175
+ */
1176
+ /**
1177
+ * This method will add entries to the precache list and add a route to
1178
+ * respond to fetch events.
1179
+ *
1180
+ * This is a convenience method that will call
1181
+ * [precache()]{@link module:workbox-precaching.precache} and
1182
+ * [addRoute()]{@link module:workbox-precaching.addRoute} in a single call.
1183
+ *
1184
+ * @param {Array<Object|string>} entries Array of entries to precache.
1185
+ * @param {Object} [options] See
1186
+ * [addRoute() options]{@link module:workbox-precaching.addRoute}.
1187
+ *
1188
+ * @memberof module:workbox-precaching
1189
+ */
1190
+
1191
+ function precacheAndRoute(entries, options) {
1192
+ precache(entries);
1193
+ addRoute(options);
1194
+ }
1195
+
1196
+ exports.PrecacheController = PrecacheController;
1197
+ exports.addPlugins = addPlugins;
1198
+ exports.addRoute = addRoute;
1199
+ exports.cleanupOutdatedCaches = cleanupOutdatedCaches;
1200
+ exports.createHandler = createHandler;
1201
+ exports.createHandlerBoundToURL = createHandlerBoundToURL;
1202
+ exports.getCacheKeyForURL = getCacheKeyForURL$1;
1203
+ exports.matchPrecache = matchPrecache;
1204
+ exports.precache = precache;
1205
+ exports.precacheAndRoute = precacheAndRoute;
1206
+
1207
+ return exports;
1208
+
1209
+ }({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core));
1210
+ //# sourceMappingURL=workbox-precaching.dev.js.map