jekyll-pwa-workbox 0.0.7.alpha → 5.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll-pwa-workbox.rb +4 -4
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-background-sync.dev.js +68 -69
- data/lib/vendor/workbox-v5.1.4/workbox-background-sync.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-background-sync.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-background-sync.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.dev.js +288 -0
- data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-cacheable-response.dev.js +6 -7
- data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-core.dev.js +490 -275
- data/lib/vendor/workbox-v5.1.4/workbox-core.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-core.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-core.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-expiration.dev.js +14 -17
- data/lib/vendor/workbox-v5.1.4/workbox-expiration.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-expiration.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-expiration.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-navigation-preload.dev.js +4 -5
- data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-offline-ga.dev.js +13 -14
- data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-precaching.dev.js +313 -97
- data/lib/vendor/workbox-v5.1.4/workbox-precaching.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-precaching.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-precaching.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-range-requests.dev.js +8 -9
- data/lib/vendor/workbox-v5.1.4/workbox-range-requests.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-range-requests.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-range-requests.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-routing.dev.js +83 -186
- data/lib/vendor/workbox-v5.1.4/workbox-routing.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-routing.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-routing.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-strategies.dev.js +30 -234
- data/lib/vendor/workbox-v5.1.4/workbox-strategies.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-strategies.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-strategies.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-streams.dev.js +16 -31
- data/lib/vendor/workbox-v5.1.4/workbox-streams.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-streams.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-streams.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-sw.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-sw.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-window.dev.es5.mjs +481 -227
- data/lib/vendor/workbox-v5.1.4/workbox-window.dev.es5.mjs.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-window.dev.mjs +246 -46
- data/lib/vendor/workbox-v5.1.4/workbox-window.dev.mjs.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.1.4}/workbox-window.dev.umd.js +483 -229
- data/lib/vendor/workbox-v5.1.4/workbox-window.dev.umd.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.es5.mjs +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.es5.mjs.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.mjs +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.mjs.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.umd.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.umd.js.map +1 -0
- metadata +69 -69
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js +0 -486
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.es5.mjs.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.mjs.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.umd.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js.map +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workbox-broadcast-update.dev.js","sources":["../_version.js","../responsesAreSame.js","../utils/constants.js","../BroadcastCacheUpdate.js","../BroadcastUpdatePlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:broadcast-update:5.1.4'] && _();\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 { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\n/**\n * Given two `Response's`, compares several header values to see if they are\n * the same or not.\n *\n * @param {Response} firstResponse\n * @param {Response} secondResponse\n * @param {Array<string>} headersToCheck\n * @return {boolean}\n *\n * @memberof module:workbox-broadcast-update\n */\nconst responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {\n if (process.env.NODE_ENV !== 'production') {\n if (!(firstResponse instanceof Response &&\n secondResponse instanceof Response)) {\n throw new WorkboxError('invalid-responses-are-same-args');\n }\n }\n const atLeastOneHeaderAvailable = headersToCheck.some((header) => {\n return firstResponse.headers.has(header) &&\n secondResponse.headers.has(header);\n });\n if (!atLeastOneHeaderAvailable) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to determine where the response has been updated ` +\n `because none of the headers that would be checked are present.`);\n logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);\n }\n // Just return true, indicating the that responses are the same, since we\n // can't determine otherwise.\n return true;\n }\n return headersToCheck.every((header) => {\n const headerStateComparison = firstResponse.headers.has(header) ===\n secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) ===\n secondResponse.headers.get(header);\n return headerStateComparison && headerValueComparison;\n });\n};\nexport { responsesAreSame };\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 CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';\nexport const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';\nexport const DEFAULT_HEADERS_TO_CHECK = [\n 'content-length',\n 'etag',\n 'last-modified',\n];\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 { assert } from 'workbox-core/_private/assert.js';\nimport { timeout } from 'workbox-core/_private/timeout.js';\nimport { resultingClientExists } from 'workbox-core/_private/resultingClientExists.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { responsesAreSame } from './responsesAreSame.js';\nimport { CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META, DEFAULT_HEADERS_TO_CHECK } from './utils/constants.js';\nimport './_version.js';\n// UA-sniff Safari: https://stackoverflow.com/questions/7944460/detect-safari-browser\n// TODO(philipwalton): remove once this Safari bug fix has been released.\n// https://bugs.webkit.org/show_bug.cgi?id=201169\nconst isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n/**\n * Generates the default payload used in update messages. By default the\n * payload includes the `cacheName` and `updatedURL` fields.\n *\n * @return Object\n * @private\n */\nfunction defaultPayloadGenerator(data) {\n return {\n cacheName: data.cacheName,\n updatedURL: data.request.url,\n };\n}\n/**\n * Uses the `postMessage()` API to inform any open windows/tabs when a cached\n * response has been updated.\n *\n * For efficiency's sake, the underlying response bodies are not compared;\n * only specific response headers are checked.\n *\n * @memberof module:workbox-broadcast-update\n */\nclass BroadcastCacheUpdate {\n /**\n * Construct a BroadcastCacheUpdate instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {Object} options\n * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.generatePayload] A function whose return value\n * will be used as the `payload` field in any cache update messages sent\n * to the window clients.\n */\n constructor({ headersToCheck, generatePayload, } = {}) {\n this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;\n this._generatePayload = generatePayload || defaultPayloadGenerator;\n }\n /**\n * Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * and sends a message (via `postMessage()`) to all window clients if the\n * responses differ (note: neither of the Responses can be\n * {@link http://stackoverflow.com/questions/39109789|opaque}).\n *\n * The message that's posted has the following format (where `payload` can\n * be customized via the `generatePayload` option the instance is created\n * with):\n *\n * ```\n * {\n * type: 'CACHE_UPDATED',\n * meta: 'workbox-broadcast-update',\n * payload: {\n * cacheName: 'the-cache-name',\n * updatedURL: 'https://example.com/'\n * }\n * }\n * ```\n *\n * @param {Object} options\n * @param {Response} [options.oldResponse] Cached response to compare.\n * @param {Response} options.newResponse Possibly updated response to compare.\n * @param {Request} options.request The request.\n * @param {string} options.cacheName Name of the cache the responses belong\n * to. This is included in the broadcast message.\n * @param {Event} [options.event] event An optional event that triggered\n * this possible cache update.\n * @return {Promise} Resolves once the update is sent.\n */\n async notifyIfUpdated(options) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(options.cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'cacheName',\n });\n assert.isInstance(options.newResponse, Response, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'newResponse',\n });\n assert.isInstance(options.request, Request, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'request',\n });\n }\n // Without two responses there is nothing to compare.\n if (!options.oldResponse) {\n return;\n }\n if (!responsesAreSame(options.oldResponse, options.newResponse, this._headersToCheck)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Newer response found (and cached) for:`, options.request.url);\n }\n const messageData = {\n type: CACHE_UPDATED_MESSAGE_TYPE,\n meta: CACHE_UPDATED_MESSAGE_META,\n payload: this._generatePayload(options),\n };\n // For navigation requests, wait until the new window client exists\n // before sending the message\n if (options.request.mode === 'navigate') {\n let resultingClientId;\n if (options.event instanceof FetchEvent) {\n resultingClientId = options.event.resultingClientId;\n }\n const resultingWin = await resultingClientExists(resultingClientId);\n // Safari does not currently implement postMessage buffering and\n // there's no good way to feature detect that, so to increase the\n // chances of the message being delivered in Safari, we add a timeout.\n // We also do this if `resultingClientExists()` didn't return a client,\n // which means it timed out, so it's worth waiting a bit longer.\n if (!resultingWin || isSafari) {\n // 3500 is chosen because (according to CrUX data) 80% of mobile\n // websites hit the DOMContentLoaded event in less than 3.5 seconds.\n // And presumably sites implementing service worker are on the\n // higher end of the performance spectrum.\n await timeout(3500);\n }\n }\n const windows = await self.clients.matchAll({ type: 'window' });\n for (const win of windows) {\n win.postMessage(messageData);\n }\n }\n }\n}\nexport { BroadcastCacheUpdate };\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 { dontWaitFor } from 'workbox-core/_private/dontWaitFor.js';\nimport { BroadcastCacheUpdate } from './BroadcastCacheUpdate.js';\nimport './_version.js';\n/**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof module:workbox-broadcast-update\n */\nclass BroadcastUpdatePlugin {\n /**\n * Construct a BroadcastCacheUpdate instance with the passed options and\n * calls its [`notifyIfUpdated()`]{@link module:workbox-broadcast-update.BroadcastCacheUpdate~notifyIfUpdated}\n * method whenever the plugin's `cacheDidUpdate` callback is invoked.\n *\n * @param {Object} options\n * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.generatePayload] A function whose return value\n * will be used as the `payload` field in any cache update messages sent\n * to the window clients.\n */\n constructor(options) {\n /**\n * A \"lifecycle\" callback that will be triggered automatically by the\n * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is\n * added to a cache.\n *\n * @private\n * @param {Object} options The input object to this function.\n * @param {string} options.cacheName Name of the cache being updated.\n * @param {Response} [options.oldResponse] The previous cached value, if any.\n * @param {Response} options.newResponse The new value in the cache.\n * @param {Request} options.request The request that triggered the update.\n * @param {Request} [options.event] The event that triggered the update.\n */\n this.cacheDidUpdate = async (options) => {\n dontWaitFor(this._broadcastUpdate.notifyIfUpdated(options));\n };\n this._broadcastUpdate = new BroadcastCacheUpdate(options);\n }\n}\nexport { BroadcastUpdatePlugin };\n"],"names":["self","_","e","responsesAreSame","firstResponse","secondResponse","headersToCheck","Response","WorkboxError","atLeastOneHeaderAvailable","some","header","headers","has","logger","warn","debug","every","headerStateComparison","headerValueComparison","get","CACHE_UPDATED_MESSAGE_TYPE","CACHE_UPDATED_MESSAGE_META","DEFAULT_HEADERS_TO_CHECK","isSafari","test","navigator","userAgent","defaultPayloadGenerator","data","cacheName","updatedURL","request","url","BroadcastCacheUpdate","constructor","generatePayload","_headersToCheck","_generatePayload","notifyIfUpdated","options","assert","isType","moduleName","className","funcName","paramName","isInstance","newResponse","Request","oldResponse","log","messageData","type","meta","payload","mode","resultingClientId","event","FetchEvent","resultingWin","resultingClientExists","timeout","windows","clients","matchAll","win","postMessage","BroadcastUpdatePlugin","cacheDidUpdate","dontWaitFor","_broadcastUpdate"],"mappings":";;;;IAEA,IAAI;IACAA,EAAAA,IAAI,CAAC,gCAAD,CAAJ,IAA0CC,CAAC,EAA3C;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICLV;;;;;;;AAOA,IAGA;;;;;;;;;;;;AAWA,UAAMC,gBAAgB,GAAG,CAACC,aAAD,EAAgBC,cAAhB,EAAgCC,cAAhC,KAAmD;IACxE,EAA2C;IACvC,QAAI,EAAEF,aAAa,YAAYG,QAAzB,IACFF,cAAc,YAAYE,QAD1B,CAAJ,EACyC;IACrC,YAAM,IAAIC,4BAAJ,CAAiB,iC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K,OAAD,EAAU;IACjB;;;;;;;;;;;;;IAaA,SAAK6B,cAAL,GAAsB,MAAO7B,OAAP,IAAmB;IACrC8B,MAAAA,0BAAW,CAAC,KAAKC,gBAAL,CAAsBhC,eAAtB,CAAsCC,OAAtC,CAAD,CAAX;IACH,KAFD;;IAGA,SAAK+B,gBAAL,GAAwB,IAAIrC,oBAAJ,CAAyBM,OAAzB,CAAxB;IACH;;IAhCuB;;;;;;;;;;;;"}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(t,a,o,s){"use strict";try{self["workbox:broadcast-update:5.1.4"]&&_()}catch(t){}const e=(t,a,o)=>!o.some(o=>t.headers.has(o)&&a.headers.has(o))||o.every(o=>{const s=t.headers.has(o)===a.headers.has(o),e=t.headers.get(o)===a.headers.get(o);return s&&e}),n=["content-length","etag","last-modified"],i=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function c(t){return{cacheName:t.cacheName,updatedURL:t.request.url}}class r{constructor({headersToCheck:t,generatePayload:a}={}){this.t=t||n,this.o=a||c}async notifyIfUpdated(t){if(t.oldResponse&&!e(t.oldResponse,t.newResponse,this.t)){const s={type:"CACHE_UPDATED",meta:"workbox-broadcast-update",payload:this.o(t)};if("navigate"===t.request.mode){let s;t.event instanceof FetchEvent&&(s=t.event.resultingClientId);await o.resultingClientExists(s)&&!i||await a.timeout(3500)}const e=await self.clients.matchAll({type:"window"});for(const t of e)t.postMessage(s)}}}return t.BroadcastCacheUpdate=r,t.BroadcastUpdatePlugin=class{constructor(t){this.cacheDidUpdate=async t=>{s.dontWaitFor(this.s.notifyIfUpdated(t))},this.s=new r(t)}},t.responsesAreSame=e,t}({},workbox.core._private,workbox.core._private,workbox.core._private);
|
2
|
+
//# sourceMappingURL=workbox-broadcast-update.prod.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workbox-broadcast-update.prod.js","sources":["../_version.js","../responsesAreSame.js","../utils/constants.js","../BroadcastCacheUpdate.js","../BroadcastUpdatePlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:broadcast-update:5.1.4'] && _();\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 { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\n/**\n * Given two `Response's`, compares several header values to see if they are\n * the same or not.\n *\n * @param {Response} firstResponse\n * @param {Response} secondResponse\n * @param {Array<string>} headersToCheck\n * @return {boolean}\n *\n * @memberof module:workbox-broadcast-update\n */\nconst responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {\n if (process.env.NODE_ENV !== 'production') {\n if (!(firstResponse instanceof Response &&\n secondResponse instanceof Response)) {\n throw new WorkboxError('invalid-responses-are-same-args');\n }\n }\n const atLeastOneHeaderAvailable = headersToCheck.some((header) => {\n return firstResponse.headers.has(header) &&\n secondResponse.headers.has(header);\n });\n if (!atLeastOneHeaderAvailable) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to determine where the response has been updated ` +\n `because none of the headers that would be checked are present.`);\n logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);\n }\n // Just return true, indicating the that responses are the same, since we\n // can't determine otherwise.\n return true;\n }\n return headersToCheck.every((header) => {\n const headerStateComparison = firstResponse.headers.has(header) ===\n secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) ===\n secondResponse.headers.get(header);\n return headerStateComparison && headerValueComparison;\n });\n};\nexport { responsesAreSame };\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 CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';\nexport const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';\nexport const DEFAULT_HEADERS_TO_CHECK = [\n 'content-length',\n 'etag',\n 'last-modified',\n];\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 { assert } from 'workbox-core/_private/assert.js';\nimport { timeout } from 'workbox-core/_private/timeout.js';\nimport { resultingClientExists } from 'workbox-core/_private/resultingClientExists.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { responsesAreSame } from './responsesAreSame.js';\nimport { CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META, DEFAULT_HEADERS_TO_CHECK } from './utils/constants.js';\nimport './_version.js';\n// UA-sniff Safari: https://stackoverflow.com/questions/7944460/detect-safari-browser\n// TODO(philipwalton): remove once this Safari bug fix has been released.\n// https://bugs.webkit.org/show_bug.cgi?id=201169\nconst isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n/**\n * Generates the default payload used in update messages. By default the\n * payload includes the `cacheName` and `updatedURL` fields.\n *\n * @return Object\n * @private\n */\nfunction defaultPayloadGenerator(data) {\n return {\n cacheName: data.cacheName,\n updatedURL: data.request.url,\n };\n}\n/**\n * Uses the `postMessage()` API to inform any open windows/tabs when a cached\n * response has been updated.\n *\n * For efficiency's sake, the underlying response bodies are not compared;\n * only specific response headers are checked.\n *\n * @memberof module:workbox-broadcast-update\n */\nclass BroadcastCacheUpdate {\n /**\n * Construct a BroadcastCacheUpdate instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {Object} options\n * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.generatePayload] A function whose return value\n * will be used as the `payload` field in any cache update messages sent\n * to the window clients.\n */\n constructor({ headersToCheck, generatePayload, } = {}) {\n this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;\n this._generatePayload = generatePayload || defaultPayloadGenerator;\n }\n /**\n * Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * and sends a message (via `postMessage()`) to all window clients if the\n * responses differ (note: neither of the Responses can be\n * {@link http://stackoverflow.com/questions/39109789|opaque}).\n *\n * The message that's posted has the following format (where `payload` can\n * be customized via the `generatePayload` option the instance is created\n * with):\n *\n * ```\n * {\n * type: 'CACHE_UPDATED',\n * meta: 'workbox-broadcast-update',\n * payload: {\n * cacheName: 'the-cache-name',\n * updatedURL: 'https://example.com/'\n * }\n * }\n * ```\n *\n * @param {Object} options\n * @param {Response} [options.oldResponse] Cached response to compare.\n * @param {Response} options.newResponse Possibly updated response to compare.\n * @param {Request} options.request The request.\n * @param {string} options.cacheName Name of the cache the responses belong\n * to. This is included in the broadcast message.\n * @param {Event} [options.event] event An optional event that triggered\n * this possible cache update.\n * @return {Promise} Resolves once the update is sent.\n */\n async notifyIfUpdated(options) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(options.cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'cacheName',\n });\n assert.isInstance(options.newResponse, Response, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'newResponse',\n });\n assert.isInstance(options.request, Request, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'request',\n });\n }\n // Without two responses there is nothing to compare.\n if (!options.oldResponse) {\n return;\n }\n if (!responsesAreSame(options.oldResponse, options.newResponse, this._headersToCheck)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Newer response found (and cached) for:`, options.request.url);\n }\n const messageData = {\n type: CACHE_UPDATED_MESSAGE_TYPE,\n meta: CACHE_UPDATED_MESSAGE_META,\n payload: this._generatePayload(options),\n };\n // For navigation requests, wait until the new window client exists\n // before sending the message\n if (options.request.mode === 'navigate') {\n let resultingClientId;\n if (options.event instanceof FetchEvent) {\n resultingClientId = options.event.resultingClientId;\n }\n const resultingWin = await resultingClientExists(resultingClientId);\n // Safari does not currently implement postMessage buffering and\n // there's no good way to feature detect that, so to increase the\n // chances of the message being delivered in Safari, we add a timeout.\n // We also do this if `resultingClientExists()` didn't return a client,\n // which means it timed out, so it's worth waiting a bit longer.\n if (!resultingWin || isSafari) {\n // 3500 is chosen because (according to CrUX data) 80% of mobile\n // websites hit the DOMContentLoaded event in less than 3.5 seconds.\n // And presumably sites implementing service worker are on the\n // higher end of the performance spectrum.\n await timeout(3500);\n }\n }\n const windows = await self.clients.matchAll({ type: 'window' });\n for (const win of windows) {\n win.postMessage(messageData);\n }\n }\n }\n}\nexport { BroadcastCacheUpdate };\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 { dontWaitFor } from 'workbox-core/_private/dontWaitFor.js';\nimport { BroadcastCacheUpdate } from './BroadcastCacheUpdate.js';\nimport './_version.js';\n/**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof module:workbox-broadcast-update\n */\nclass BroadcastUpdatePlugin {\n /**\n * Construct a BroadcastCacheUpdate instance with the passed options and\n * calls its [`notifyIfUpdated()`]{@link module:workbox-broadcast-update.BroadcastCacheUpdate~notifyIfUpdated}\n * method whenever the plugin's `cacheDidUpdate` callback is invoked.\n *\n * @param {Object} options\n * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.generatePayload] A function whose return value\n * will be used as the `payload` field in any cache update messages sent\n * to the window clients.\n */\n constructor(options) {\n /**\n * A \"lifecycle\" callback that will be triggered automatically by the\n * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is\n * added to a cache.\n *\n * @private\n * @param {Object} options The input object to this function.\n * @param {string} options.cacheName Name of the cache being updated.\n * @param {Response} [options.oldResponse] The previous cached value, if any.\n * @param {Response} options.newResponse The new value in the cache.\n * @param {Request} options.request The request that triggered the update.\n * @param {Request} [options.event] The event that triggered the update.\n */\n this.cacheDidUpdate = async (options) => {\n dontWaitFor(this._broadcastUpdate.notifyIfUpdated(options));\n };\n this._broadcastUpdate = new BroadcastCacheUpdate(options);\n }\n}\nexport { BroadcastUpdatePlugin };\n"],"names":["self","_","e","responsesAreSame","firstResponse","secondResponse","headersToCheck","some","header","headers","has","every","headerStateComparison","headerValueComparison","get","DEFAULT_HEADERS_TO_CHECK","isSafari","test","navigator","userAgent","defaultPayloadGenerator","data","cacheName","updatedURL","request","url","BroadcastCacheUpdate","constructor","generatePayload","_headersToCheck","_generatePayload","options","oldResponse","newResponse","this","messageData","type","meta","payload","mode","resultingClientId","event","FetchEvent","resultingClientExists","timeout","windows","clients","matchAll","win","postMessage","cacheDidUpdate","async","dontWaitFor","_broadcastUpdate","notifyIfUpdated"],"mappings":"0FAEA,IACIA,KAAK,mCAAqCC,IAE9C,MAAOC,UCgBDC,EAAmB,CAACC,EAAeC,EAAgBC,KAOnBA,EAAeC,KAAMC,GAC5CJ,EAAcK,QAAQC,IAAIF,IAC7BH,EAAeI,QAAQC,IAAIF,KAY5BF,EAAeK,MAAOH,UACnBI,EAAwBR,EAAcK,QAAQC,IAAIF,KACpDH,EAAeI,QAAQC,IAAIF,GACzBK,EAAwBT,EAAcK,QAAQK,IAAIN,KACpDH,EAAeI,QAAQK,IAAIN,UACxBI,GAAyBC,ICrC3BE,EAA2B,CACpC,iBACA,OACA,iBCIEC,EAAW,iCAAiCC,KAAKC,UAAUC,WAQjE,SAASC,EAAwBC,SACtB,CACHC,UAAWD,EAAKC,UAChBC,WAAYF,EAAKG,QAAQC,KAYjC,MAAMC,EAaFC,aAAYrB,eAAEA,EAAFsB,gBAAkBA,GAAqB,SAC1CC,EAAkBvB,GAAkBS,OACpCe,EAAmBF,GAAmBR,wBAiCzBW,MAsBbA,EAAQC,cAGR7B,EAAiB4B,EAAQC,YAAaD,EAAQE,YAAaC,KAAKL,GAAkB,OAI7EM,EAAc,CAChBC,KD9G0B,gBC+G1BC,KD9G0B,2BC+G1BC,QAASJ,KAAKJ,EAAiBC,OAIN,aAAzBA,EAAQP,QAAQe,KAAqB,KACjCC,EACAT,EAAQU,iBAAiBC,aACzBF,EAAoBT,EAAQU,MAAMD,yBAEXG,wBAAsBH,KAM5BxB,SAKX4B,UAAQ,YAGhBC,QAAgB7C,KAAK8C,QAAQC,SAAS,CAAEX,KAAM,eAC/C,MAAMY,KAAOH,EACdG,EAAIC,YAAYd,6DCjIhC,MAcIR,YAAYI,QAcHmB,eAAiBC,MAAAA,IAClBC,cAAYlB,KAAKmB,EAAiBC,gBAAgBvB,UAEjDsB,EAAmB,IAAI3B,EAAqBK"}
|
@@ -2,9 +2,8 @@ this.workbox = this.workbox || {};
|
|
2
2
|
this.workbox.cacheableResponse = (function (exports, assert_js, WorkboxError_js, getFriendlyURL_js, logger_js) {
|
3
3
|
'use strict';
|
4
4
|
|
5
|
-
// @ts-ignore
|
6
5
|
try {
|
7
|
-
self['workbox:cacheable-response:5.
|
6
|
+
self['workbox:cacheable-response:5.1.4'] && _();
|
8
7
|
} catch (e) {}
|
9
8
|
|
10
9
|
/*
|
@@ -20,7 +19,7 @@ this.workbox.cacheableResponse = (function (exports, assert_js, WorkboxError_js,
|
|
20
19
|
* [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
21
20
|
* to be considered cacheable.
|
22
21
|
*
|
23
|
-
* @memberof workbox
|
22
|
+
* @memberof module:workbox-cacheable-response
|
24
23
|
*/
|
25
24
|
|
26
25
|
class CacheableResponse {
|
@@ -143,12 +142,12 @@ this.workbox.cacheableResponse = (function (exports, assert_js, WorkboxError_js,
|
|
143
142
|
* easier to add in cacheability checks to requests made via Workbox's built-in
|
144
143
|
* strategies.
|
145
144
|
*
|
146
|
-
* @memberof workbox
|
145
|
+
* @memberof module:workbox-cacheable-response
|
147
146
|
*/
|
148
147
|
|
149
|
-
class
|
148
|
+
class CacheableResponsePlugin {
|
150
149
|
/**
|
151
|
-
* To construct a new
|
150
|
+
* To construct a new CacheableResponsePlugin instance you must provide at
|
152
151
|
* least one of the `config` properties.
|
153
152
|
*
|
154
153
|
* If both `statuses` and `headers` are specified, then both conditions must
|
@@ -184,7 +183,7 @@ this.workbox.cacheableResponse = (function (exports, assert_js, WorkboxError_js,
|
|
184
183
|
}
|
185
184
|
|
186
185
|
exports.CacheableResponse = CacheableResponse;
|
187
|
-
exports.
|
186
|
+
exports.CacheableResponsePlugin = CacheableResponsePlugin;
|
188
187
|
|
189
188
|
return exports;
|
190
189
|
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workbox-cacheable-response.dev.js","sources":["../_version.js","../CacheableResponse.js","../CacheableResponsePlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:cacheable-response:5.1.4'] && _();\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 { assert } from 'workbox-core/_private/assert.js';\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\n/**\n * This class allows you to set up rules determining what\n * status codes and/or headers need to be present in order for a\n * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * to be considered cacheable.\n *\n * @memberof module:workbox-cacheable-response\n */\nclass CacheableResponse {\n /**\n * To construct a new CacheableResponse instance you must provide at least\n * one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config = {}) {\n if (process.env.NODE_ENV !== 'production') {\n if (!(config.statuses || config.headers)) {\n throw new WorkboxError('statuses-or-headers-required', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n });\n }\n if (config.statuses) {\n assert.isArray(config.statuses, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.statuses',\n });\n }\n if (config.headers) {\n assert.isType(config.headers, 'object', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.headers',\n });\n }\n }\n this._statuses = config.statuses;\n this._headers = config.headers;\n }\n /**\n * Checks a response to see whether it's cacheable or not, based on this\n * object's configuration.\n *\n * @param {Response} response The response whose cacheability is being\n * checked.\n * @return {boolean} `true` if the `Response` is cacheable, and `false`\n * otherwise.\n */\n isResponseCacheable(response) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(response, Response, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'isResponseCacheable',\n paramName: 'response',\n });\n }\n let cacheable = true;\n if (this._statuses) {\n cacheable = this._statuses.includes(response.status);\n }\n if (this._headers && cacheable) {\n cacheable = Object.keys(this._headers).some((headerName) => {\n return response.headers.get(headerName) === this._headers[headerName];\n });\n }\n if (process.env.NODE_ENV !== 'production') {\n if (!cacheable) {\n logger.groupCollapsed(`The request for ` +\n `'${getFriendlyURL(response.url)}' returned a response that does ` +\n `not meet the criteria for being cached.`);\n logger.groupCollapsed(`View cacheability criteria here.`);\n logger.log(`Cacheable statuses: ` +\n JSON.stringify(this._statuses));\n logger.log(`Cacheable headers: ` +\n JSON.stringify(this._headers, null, 2));\n logger.groupEnd();\n const logFriendlyHeaders = {};\n response.headers.forEach((value, key) => {\n logFriendlyHeaders[key] = value;\n });\n logger.groupCollapsed(`View response status and headers here.`);\n logger.log(`Response status: ` + response.status);\n logger.log(`Response headers: ` +\n JSON.stringify(logFriendlyHeaders, null, 2));\n logger.groupEnd();\n logger.groupCollapsed(`View full response details here.`);\n logger.log(response.headers);\n logger.log(response);\n logger.groupEnd();\n logger.groupEnd();\n }\n }\n return cacheable;\n }\n}\nexport { CacheableResponse };\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 { CacheableResponse } from './CacheableResponse.js';\nimport './_version.js';\n/**\n * A class implementing the `cacheWillUpdate` lifecycle callback. This makes it\n * easier to add in cacheability checks to requests made via Workbox's built-in\n * strategies.\n *\n * @memberof module:workbox-cacheable-response\n */\nclass CacheableResponsePlugin {\n /**\n * To construct a new CacheableResponsePlugin instance you must provide at\n * least one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config) {\n /**\n * @param {Object} options\n * @param {Response} options.response\n * @return {Response|null}\n * @private\n */\n this.cacheWillUpdate = async ({ response }) => {\n if (this._cacheableResponse.isResponseCacheable(response)) {\n return response;\n }\n return null;\n };\n this._cacheableResponse = new CacheableResponse(config);\n }\n}\nexport { CacheableResponsePlugin };\n"],"names":["self","_","e","CacheableResponse","constructor","config","statuses","headers","WorkboxError","moduleName","className","funcName","assert","isArray","paramName","isType","_statuses","_headers","isResponseCacheable","response","isInstance","Response","cacheable","includes","status","Object","keys","some","headerName","get","logger","groupCollapsed","getFriendlyURL","url","log","JSON","stringify","groupEnd","logFriendlyHeaders","forEach","value","key","CacheableResponsePlugin","cacheWillUpdate","_cacheableResponse"],"mappings":";;;;IAEA,IAAI;IACAA,EAAAA,IAAI,CAAC,kCAAD,CAAJ,IAA4CC,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CAAlB,GAA0BD,KAA1B;IACH,SAFD;IAGAV,QAAAA,gBAAM,CAACC,cAAP,CAAuB,wCAAvB;IACAD,QAAAA,gBAAM,CAACI,GAAP,CAAY,mBAAD,GAAsBf,QAAQ,CAACK,MAA1C;IACAM,QAAAA,gBAAM,CAACI,GAAP,CAAY,oBAAD,GACPC,IAAI,CAACC,SAAL,CAAeE,kBAAf,EAAmC,IAAnC,EAAyC,CAAzC,CADJ;IAEAR,QAAAA,gBAAM,CAACO,QAAP;IACAP,QAAAA,gBAAM,CAACC,cAAP,CAAuB,kCAAvB;IACAD,QAAAA,gBAAM,CAACI,GAAP,CAAWf,QAAQ,CAACZ,OAApB;IACAuB,QAAAA,gBAAM,CAACI,GAAP,CAAWf,QAAX;IACAW,QAAAA,gBAAM,CAACO,QAAP;IACAP,QAAAA,gBAAM,CAACO,QAAP;IACH;IACJ;;IACD,WAAOf,SAAP;IACH;;IAnGmB;;ICpBxB;;;;;;;AAOA,IAEA;;;;;;;;IAOA,MAAMoB,uBAAN,CAA8B;IAC1B;;;;;;;;;;;;;;IAcAtC,EAAAA,WAAW,CAACC,MAAD,EAAS;IAChB;;;;;;IAMA,SAAKsC,eAAL,GAAuB,OAAO;IAAExB,MAAAA;IAAF,KAAP,KAAwB;IAC3C,UAAI,KAAKyB,kBAAL,CAAwB1B,mBAAxB,CAA4CC,QAA5C,CAAJ,EAA2D;IACvD,eAAOA,QAAP;IACH;;IACD,aAAO,IAAP;IACH,KALD;;IAMA,SAAKyB,kBAAL,GAA0B,IAAIzC,iBAAJ,CAAsBE,MAAtB,CAA1B;IACH;;IA7ByB;;;;;;;;;;;"}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
this.workbox=this.workbox||{},this.workbox.cacheableResponse=function(s){"use strict";try{self["workbox:cacheable-response:5.1.4"]&&_()}catch(s){}class t{constructor(s={}){this.s=s.statuses,this.t=s.headers}isResponseCacheable(s){let t=!0;return this.s&&(t=this.s.includes(s.status)),this.t&&t&&(t=Object.keys(this.t).some(t=>s.headers.get(t)===this.t[t])),t}}return s.CacheableResponse=t,s.CacheableResponsePlugin=class{constructor(s){this.cacheWillUpdate=async({response:s})=>this.i.isResponseCacheable(s)?s:null,this.i=new t(s)}},s}({});
|
2
|
+
//# sourceMappingURL=workbox-cacheable-response.prod.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workbox-cacheable-response.prod.js","sources":["../_version.js","../CacheableResponse.js","../CacheableResponsePlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:cacheable-response:5.1.4'] && _();\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 { assert } from 'workbox-core/_private/assert.js';\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\n/**\n * This class allows you to set up rules determining what\n * status codes and/or headers need to be present in order for a\n * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * to be considered cacheable.\n *\n * @memberof module:workbox-cacheable-response\n */\nclass CacheableResponse {\n /**\n * To construct a new CacheableResponse instance you must provide at least\n * one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config = {}) {\n if (process.env.NODE_ENV !== 'production') {\n if (!(config.statuses || config.headers)) {\n throw new WorkboxError('statuses-or-headers-required', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n });\n }\n if (config.statuses) {\n assert.isArray(config.statuses, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.statuses',\n });\n }\n if (config.headers) {\n assert.isType(config.headers, 'object', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.headers',\n });\n }\n }\n this._statuses = config.statuses;\n this._headers = config.headers;\n }\n /**\n * Checks a response to see whether it's cacheable or not, based on this\n * object's configuration.\n *\n * @param {Response} response The response whose cacheability is being\n * checked.\n * @return {boolean} `true` if the `Response` is cacheable, and `false`\n * otherwise.\n */\n isResponseCacheable(response) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(response, Response, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'isResponseCacheable',\n paramName: 'response',\n });\n }\n let cacheable = true;\n if (this._statuses) {\n cacheable = this._statuses.includes(response.status);\n }\n if (this._headers && cacheable) {\n cacheable = Object.keys(this._headers).some((headerName) => {\n return response.headers.get(headerName) === this._headers[headerName];\n });\n }\n if (process.env.NODE_ENV !== 'production') {\n if (!cacheable) {\n logger.groupCollapsed(`The request for ` +\n `'${getFriendlyURL(response.url)}' returned a response that does ` +\n `not meet the criteria for being cached.`);\n logger.groupCollapsed(`View cacheability criteria here.`);\n logger.log(`Cacheable statuses: ` +\n JSON.stringify(this._statuses));\n logger.log(`Cacheable headers: ` +\n JSON.stringify(this._headers, null, 2));\n logger.groupEnd();\n const logFriendlyHeaders = {};\n response.headers.forEach((value, key) => {\n logFriendlyHeaders[key] = value;\n });\n logger.groupCollapsed(`View response status and headers here.`);\n logger.log(`Response status: ` + response.status);\n logger.log(`Response headers: ` +\n JSON.stringify(logFriendlyHeaders, null, 2));\n logger.groupEnd();\n logger.groupCollapsed(`View full response details here.`);\n logger.log(response.headers);\n logger.log(response);\n logger.groupEnd();\n logger.groupEnd();\n }\n }\n return cacheable;\n }\n}\nexport { CacheableResponse };\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 { CacheableResponse } from './CacheableResponse.js';\nimport './_version.js';\n/**\n * A class implementing the `cacheWillUpdate` lifecycle callback. This makes it\n * easier to add in cacheability checks to requests made via Workbox's built-in\n * strategies.\n *\n * @memberof module:workbox-cacheable-response\n */\nclass CacheableResponsePlugin {\n /**\n * To construct a new CacheableResponsePlugin instance you must provide at\n * least one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config) {\n /**\n * @param {Object} options\n * @param {Response} options.response\n * @return {Response|null}\n * @private\n */\n this.cacheWillUpdate = async ({ response }) => {\n if (this._cacheableResponse.isResponseCacheable(response)) {\n return response;\n }\n return null;\n };\n this._cacheableResponse = new CacheableResponse(config);\n }\n}\nexport { CacheableResponsePlugin };\n"],"names":["self","_","e","CacheableResponse","constructor","config","_statuses","statuses","_headers","headers","isResponseCacheable","response","cacheable","this","includes","status","Object","keys","some","headerName","get","cacheWillUpdate","async","_cacheableResponse"],"mappings":"sFAEA,IACIA,KAAK,qCAAuCC,IAEhD,MAAOC,ICeP,MAAMC,EAeFC,YAAYC,EAAS,SA0BZC,EAAYD,EAAOE,cACnBC,EAAWH,EAAOI,QAW3BC,oBAAoBC,OASZC,GAAY,SACZC,KAAKP,IACLM,EAAYC,KAAKP,EAAUQ,SAASH,EAASI,SAE7CF,KAAKL,GAAYI,IACjBA,EAAYI,OAAOC,KAAKJ,KAAKL,GAAUU,KAAMC,GAClCR,EAASF,QAAQW,IAAID,KAAgBN,KAAKL,EAASW,KA8B3DP,0DCtGf,MAeIR,YAAYC,QAOHgB,gBAAkBC,OAASX,SAAAA,KACxBE,KAAKU,EAAmBb,oBAAoBC,GACrCA,EAEJ,UAENY,EAAqB,IAAIpB,EAAkBE"}
|
@@ -2,9 +2,8 @@ this.workbox = this.workbox || {};
|
|
2
2
|
this.workbox.core = (function (exports) {
|
3
3
|
'use strict';
|
4
4
|
|
5
|
-
// @ts-ignore
|
6
5
|
try {
|
7
|
-
self['workbox:core:5.
|
6
|
+
self['workbox:core:5.1.4'] && _();
|
8
7
|
} catch (e) {}
|
9
8
|
|
10
9
|
/*
|
@@ -14,6 +13,12 @@ this.workbox.core = (function (exports) {
|
|
14
13
|
https://opensource.org/licenses/MIT.
|
15
14
|
*/
|
16
15
|
const logger = (() => {
|
16
|
+
// Don't overwrite this value if it's already set.
|
17
|
+
// See https://github.com/GoogleChrome/workbox/pull/2284#issuecomment-560470923
|
18
|
+
if (!('__WB_DISABLE_DEV_LOGS' in self)) {
|
19
|
+
self.__WB_DISABLE_DEV_LOGS = false;
|
20
|
+
}
|
21
|
+
|
17
22
|
let inGroup = false;
|
18
23
|
const methodToColorMap = {
|
19
24
|
debug: `#7f8c8d`,
|
@@ -25,6 +30,10 @@ this.workbox.core = (function (exports) {
|
|
25
30
|
};
|
26
31
|
|
27
32
|
const print = function (method, args) {
|
33
|
+
if (self.__WB_DISABLE_DEV_LOGS) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
|
28
37
|
if (method === 'groupCollapsed') {
|
29
38
|
// Safari doesn't print all console.groupCollapsed() arguments:
|
30
39
|
// https://bugs.webkit.org/show_bug.cgi?id=182754
|
@@ -81,15 +90,6 @@ this.workbox.core = (function (exports) {
|
|
81
90
|
|
82
91
|
return `The '${paramName}' parameter was given a value with an ` + `unexpected value. ${validValueDescription} Received a value of ` + `${JSON.stringify(value)}.`;
|
83
92
|
},
|
84
|
-
'not-in-sw': ({
|
85
|
-
moduleName
|
86
|
-
}) => {
|
87
|
-
if (!moduleName) {
|
88
|
-
throw new Error(`Unexpected input to 'not-in-sw' error.`);
|
89
|
-
}
|
90
|
-
|
91
|
-
return `The '${moduleName}' must be used in a service worker.`;
|
92
|
-
},
|
93
93
|
'not-an-array': ({
|
94
94
|
moduleName,
|
95
95
|
className,
|
@@ -159,7 +159,7 @@ this.workbox.core = (function (exports) {
|
|
159
159
|
throw new Error(`Unexpected input to ` + `'add-to-cache-list-duplicate-entries' error.`);
|
160
160
|
}
|
161
161
|
|
162
|
-
return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` + `${firstEntry._entryId} but different revision details. Workbox is ` + `
|
162
|
+
return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` + `${firstEntry._entryId} but different revision details. Workbox is ` + `unable to cache and version the asset correctly. Please remove one ` + `of the entries.`;
|
163
163
|
},
|
164
164
|
'plugin-error-request-will-fetch': ({
|
165
165
|
thrownError
|
@@ -178,7 +178,7 @@ this.workbox.core = (function (exports) {
|
|
178
178
|
throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
|
179
179
|
}
|
180
180
|
|
181
|
-
return `You must provide a name containing at least one character for ` + `
|
181
|
+
return `You must provide a name containing at least one character for ` + `setCacheDetails({${cacheNameId}: '...'}). Received a value of ` + `'${JSON.stringify(value)}'`;
|
182
182
|
},
|
183
183
|
'unregister-route-but-not-found-with-method': ({
|
184
184
|
method
|
@@ -325,6 +325,22 @@ this.workbox.core = (function (exports) {
|
|
325
325
|
status
|
326
326
|
}) => {
|
327
327
|
return `The precaching request for '${url}' failed with an HTTP ` + `status of ${status}.`;
|
328
|
+
},
|
329
|
+
'non-precached-url': ({
|
330
|
+
url
|
331
|
+
}) => {
|
332
|
+
return `createHandlerBoundToURL('${url}') was called, but that URL is ` + `not precached. Please pass in a URL that is precached instead.`;
|
333
|
+
},
|
334
|
+
'add-to-cache-list-conflicting-integrities': ({
|
335
|
+
url
|
336
|
+
}) => {
|
337
|
+
return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` + `${url} with different integrity values. Please remove one of them.`;
|
338
|
+
},
|
339
|
+
'missing-precache-entry': ({
|
340
|
+
cacheName,
|
341
|
+
url
|
342
|
+
}) => {
|
343
|
+
return `Unable to find a precached response in ${cacheName} for ${url}.`;
|
328
344
|
}
|
329
345
|
};
|
330
346
|
|
@@ -375,7 +391,7 @@ this.workbox.core = (function (exports) {
|
|
375
391
|
* be added as a key on the context object.
|
376
392
|
*/
|
377
393
|
constructor(errorCode, details) {
|
378
|
-
|
394
|
+
const message = messageGenerator(errorCode, details);
|
379
395
|
super(message);
|
380
396
|
this.name = errorCode;
|
381
397
|
this.details = details;
|
@@ -390,17 +406,6 @@ this.workbox.core = (function (exports) {
|
|
390
406
|
license that can be found in the LICENSE file or at
|
391
407
|
https://opensource.org/licenses/MIT.
|
392
408
|
*/
|
393
|
-
/*
|
394
|
-
* This method returns true if the current context is a service worker.
|
395
|
-
*/
|
396
|
-
|
397
|
-
const isSWEnv = moduleName => {
|
398
|
-
if (!('ServiceWorkerGlobalScope' in self)) {
|
399
|
-
throw new WorkboxError('not-in-sw', {
|
400
|
-
moduleName
|
401
|
-
});
|
402
|
-
}
|
403
|
-
};
|
404
409
|
/*
|
405
410
|
* This method throws if the supplied value is not an array.
|
406
411
|
* The destructed values are required to produce a meaningful error for users.
|
@@ -408,7 +413,6 @@ this.workbox.core = (function (exports) {
|
|
408
413
|
* needed.
|
409
414
|
*/
|
410
415
|
|
411
|
-
|
412
416
|
const isArray = (value, details) => {
|
413
417
|
if (!Array.isArray(value)) {
|
414
418
|
throw new WorkboxError('not-an-array', details);
|
@@ -419,28 +423,28 @@ this.workbox.core = (function (exports) {
|
|
419
423
|
const type = typeof object[expectedMethod];
|
420
424
|
|
421
425
|
if (type !== 'function') {
|
422
|
-
details
|
426
|
+
details['expectedMethod'] = expectedMethod;
|
423
427
|
throw new WorkboxError('missing-a-method', details);
|
424
428
|
}
|
425
429
|
};
|
426
430
|
|
427
431
|
const isType = (object, expectedType, details) => {
|
428
432
|
if (typeof object !== expectedType) {
|
429
|
-
details
|
433
|
+
details['expectedType'] = expectedType;
|
430
434
|
throw new WorkboxError('incorrect-type', details);
|
431
435
|
}
|
432
436
|
};
|
433
437
|
|
434
438
|
const isInstance = (object, expectedClass, details) => {
|
435
439
|
if (!(object instanceof expectedClass)) {
|
436
|
-
details
|
440
|
+
details['expectedClass'] = expectedClass;
|
437
441
|
throw new WorkboxError('incorrect-class', details);
|
438
442
|
}
|
439
443
|
};
|
440
444
|
|
441
445
|
const isOneOf = (value, validValues, details) => {
|
442
446
|
if (!validValues.includes(value)) {
|
443
|
-
details
|
447
|
+
details['validValueDescription'] = `Valid values are ${JSON.stringify(validValues)}.`;
|
444
448
|
throw new WorkboxError('invalid-value', details);
|
445
449
|
}
|
446
450
|
};
|
@@ -452,7 +456,7 @@ this.workbox.core = (function (exports) {
|
|
452
456
|
throw error;
|
453
457
|
}
|
454
458
|
|
455
|
-
for (
|
459
|
+
for (const item of value) {
|
456
460
|
if (!(item instanceof expectedClass)) {
|
457
461
|
throw error;
|
458
462
|
}
|
@@ -464,7 +468,6 @@ this.workbox.core = (function (exports) {
|
|
464
468
|
isArray,
|
465
469
|
isInstance,
|
466
470
|
isOneOf,
|
467
|
-
isSWEnv,
|
468
471
|
isType,
|
469
472
|
isArrayOfClass
|
470
473
|
};
|
@@ -491,7 +494,7 @@ this.workbox.core = (function (exports) {
|
|
491
494
|
* there's a quota error.
|
492
495
|
*
|
493
496
|
* @param {Function} callback
|
494
|
-
* @memberof workbox
|
497
|
+
* @memberof module:workbox-core
|
495
498
|
*/
|
496
499
|
|
497
500
|
function registerQuotaErrorCallback(callback) {
|
@@ -522,7 +525,7 @@ this.workbox.core = (function (exports) {
|
|
522
525
|
precache: 'precache-v2',
|
523
526
|
prefix: 'workbox',
|
524
527
|
runtime: 'runtime',
|
525
|
-
suffix: registration.scope
|
528
|
+
suffix: typeof registration !== 'undefined' ? registration.scope : ''
|
526
529
|
};
|
527
530
|
|
528
531
|
const _createCacheName = cacheName => {
|
@@ -560,24 +563,6 @@ this.workbox.core = (function (exports) {
|
|
560
563
|
}
|
561
564
|
};
|
562
565
|
|
563
|
-
/*
|
564
|
-
Copyright 2018 Google LLC
|
565
|
-
|
566
|
-
Use of this source code is governed by an MIT-style
|
567
|
-
license that can be found in the LICENSE file or at
|
568
|
-
https://opensource.org/licenses/MIT.
|
569
|
-
*/
|
570
|
-
|
571
|
-
const getFriendlyURL = url => {
|
572
|
-
const urlObj = new URL(String(url), location.href);
|
573
|
-
|
574
|
-
if (urlObj.origin === location.origin) {
|
575
|
-
return urlObj.pathname;
|
576
|
-
}
|
577
|
-
|
578
|
-
return urlObj.href;
|
579
|
-
};
|
580
|
-
|
581
566
|
/*
|
582
567
|
Copyright 2018 Google LLC
|
583
568
|
|
@@ -589,7 +574,7 @@ this.workbox.core = (function (exports) {
|
|
589
574
|
* Runs all of the callback functions, one at a time sequentially, in the order
|
590
575
|
* in which they were registered.
|
591
576
|
*
|
592
|
-
* @memberof workbox
|
577
|
+
* @memberof module:workbox-core
|
593
578
|
* @private
|
594
579
|
*/
|
595
580
|
|
@@ -611,6 +596,21 @@ this.workbox.core = (function (exports) {
|
|
611
596
|
}
|
612
597
|
}
|
613
598
|
|
599
|
+
/*
|
600
|
+
Copyright 2018 Google LLC
|
601
|
+
|
602
|
+
Use of this source code is governed by an MIT-style
|
603
|
+
license that can be found in the LICENSE file or at
|
604
|
+
https://opensource.org/licenses/MIT.
|
605
|
+
*/
|
606
|
+
|
607
|
+
const getFriendlyURL = url => {
|
608
|
+
const urlObj = new URL(String(url), location.href); // See https://github.com/GoogleChrome/workbox/issues/2323
|
609
|
+
// We want to include everything, except for the origin if it's same-origin.
|
610
|
+
|
611
|
+
return urlObj.href.replace(new RegExp(`^${location.origin}`), '');
|
612
|
+
};
|
613
|
+
|
614
614
|
/*
|
615
615
|
Copyright 2018 Google LLC
|
616
616
|
|
@@ -632,107 +632,130 @@ this.workbox.core = (function (exports) {
|
|
632
632
|
https://opensource.org/licenses/MIT.
|
633
633
|
*/
|
634
634
|
/**
|
635
|
-
*
|
636
|
-
*
|
637
|
-
*
|
638
|
-
*
|
635
|
+
* Checks the list of plugins for the cacheKeyWillBeUsed callback, and
|
636
|
+
* executes any of those callbacks found in sequence. The final `Request` object
|
637
|
+
* returned by the last plugin is treated as the cache key for cache reads
|
638
|
+
* and/or writes.
|
639
639
|
*
|
640
640
|
* @param {Object} options
|
641
|
-
* @param {string} options.cacheName
|
642
641
|
* @param {Request} options.request
|
643
|
-
* @param {
|
644
|
-
* @param {Event} [options.event]
|
642
|
+
* @param {string} options.mode
|
645
643
|
* @param {Array<Object>} [options.plugins=[]]
|
646
|
-
* @
|
644
|
+
* @return {Promise<Request>}
|
647
645
|
*
|
648
646
|
* @private
|
649
647
|
* @memberof module:workbox-core
|
650
648
|
*/
|
651
649
|
|
652
|
-
const
|
653
|
-
cacheName,
|
650
|
+
const _getEffectiveRequest = async ({
|
654
651
|
request,
|
655
|
-
|
656
|
-
|
657
|
-
plugins = [],
|
658
|
-
matchOptions
|
652
|
+
mode,
|
653
|
+
plugins = []
|
659
654
|
}) => {
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
method: request.method
|
665
|
-
});
|
666
|
-
}
|
667
|
-
}
|
655
|
+
const cacheKeyWillBeUsedPlugins = pluginUtils.filter(plugins, "cacheKeyWillBeUsed"
|
656
|
+
/* CACHE_KEY_WILL_BE_USED */
|
657
|
+
);
|
658
|
+
let effectiveRequest = request;
|
668
659
|
|
669
|
-
const
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
660
|
+
for (const plugin of cacheKeyWillBeUsedPlugins) {
|
661
|
+
effectiveRequest = await plugin["cacheKeyWillBeUsed"
|
662
|
+
/* CACHE_KEY_WILL_BE_USED */
|
663
|
+
].call(plugin, {
|
664
|
+
mode,
|
665
|
+
request: effectiveRequest
|
666
|
+
});
|
674
667
|
|
675
|
-
|
676
|
-
|
677
|
-
logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`);
|
668
|
+
if (typeof effectiveRequest === 'string') {
|
669
|
+
effectiveRequest = new Request(effectiveRequest);
|
678
670
|
}
|
679
671
|
|
680
|
-
|
681
|
-
|
682
|
-
|
672
|
+
{
|
673
|
+
finalAssertExports.isInstance(effectiveRequest, Request, {
|
674
|
+
moduleName: 'Plugin',
|
675
|
+
funcName: "cacheKeyWillBeUsed"
|
676
|
+
/* CACHE_KEY_WILL_BE_USED */
|
677
|
+
,
|
678
|
+
isReturnValueProblem: true
|
679
|
+
});
|
680
|
+
}
|
683
681
|
}
|
684
682
|
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
683
|
+
return effectiveRequest;
|
684
|
+
};
|
685
|
+
/**
|
686
|
+
* This method will call cacheWillUpdate on the available plugins (or use
|
687
|
+
* status === 200) to determine if the Response is safe and valid to cache.
|
688
|
+
*
|
689
|
+
* @param {Object} options
|
690
|
+
* @param {Request} options.request
|
691
|
+
* @param {Response} options.response
|
692
|
+
* @param {Event} [options.event]
|
693
|
+
* @param {Array<Object>} [options.plugins=[]]
|
694
|
+
* @return {Promise<Response>}
|
695
|
+
*
|
696
|
+
* @private
|
697
|
+
* @memberof module:workbox-core
|
698
|
+
*/
|
691
699
|
|
692
|
-
if (!responseToCache) {
|
693
|
-
{
|
694
|
-
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will ` + `not be cached.`, responseToCache);
|
695
|
-
}
|
696
700
|
|
697
|
-
|
698
|
-
|
701
|
+
const _isResponseSafeToCache = async ({
|
702
|
+
request,
|
703
|
+
response,
|
704
|
+
event,
|
705
|
+
plugins = []
|
706
|
+
}) => {
|
707
|
+
let responseToCache = response;
|
708
|
+
let pluginsUsed = false;
|
699
709
|
|
700
|
-
const
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
710
|
+
for (const plugin of plugins) {
|
711
|
+
if ("cacheWillUpdate"
|
712
|
+
/* CACHE_WILL_UPDATE */
|
713
|
+
in plugin) {
|
714
|
+
pluginsUsed = true;
|
715
|
+
const pluginMethod = plugin["cacheWillUpdate"
|
716
|
+
/* CACHE_WILL_UPDATE */
|
717
|
+
];
|
718
|
+
responseToCache = await pluginMethod.call(plugin, {
|
719
|
+
request,
|
720
|
+
response: responseToCache,
|
721
|
+
event
|
722
|
+
});
|
709
723
|
|
710
|
-
|
711
|
-
|
724
|
+
{
|
725
|
+
if (responseToCache) {
|
726
|
+
finalAssertExports.isInstance(responseToCache, Response, {
|
727
|
+
moduleName: 'Plugin',
|
728
|
+
funcName: "cacheWillUpdate"
|
729
|
+
/* CACHE_WILL_UPDATE */
|
730
|
+
,
|
731
|
+
isReturnValueProblem: true
|
732
|
+
});
|
733
|
+
}
|
734
|
+
}
|
735
|
+
|
736
|
+
if (!responseToCache) {
|
737
|
+
break;
|
738
|
+
}
|
739
|
+
}
|
712
740
|
}
|
713
741
|
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
742
|
+
if (!pluginsUsed) {
|
743
|
+
{
|
744
|
+
if (responseToCache) {
|
745
|
+
if (responseToCache.status !== 200) {
|
746
|
+
if (responseToCache.status === 0) {
|
747
|
+
logger.warn(`The response for '${request.url}' is an opaque ` + `response. The caching strategy that you're using will not ` + `cache opaque responses by default.`);
|
748
|
+
} else {
|
749
|
+
logger.debug(`The response for '${request.url}' returned ` + `a status code of '${response.status}' and won't be cached as a ` + `result.`);
|
750
|
+
}
|
751
|
+
}
|
752
|
+
}
|
720
753
|
}
|
721
754
|
|
722
|
-
|
755
|
+
responseToCache = responseToCache && responseToCache.status === 200 ? responseToCache : undefined;
|
723
756
|
}
|
724
757
|
|
725
|
-
|
726
|
-
await plugin["cacheDidUpdate"
|
727
|
-
/* CACHE_DID_UPDATE */
|
728
|
-
].call(plugin, {
|
729
|
-
cacheName,
|
730
|
-
event,
|
731
|
-
oldResponse,
|
732
|
-
newResponse: responseToCache,
|
733
|
-
request: effectiveRequest
|
734
|
-
});
|
735
|
-
}
|
758
|
+
return responseToCache ? responseToCache : null;
|
736
759
|
};
|
737
760
|
/**
|
738
761
|
* This is a wrapper around cache.match().
|
@@ -741,7 +764,7 @@ this.workbox.core = (function (exports) {
|
|
741
764
|
* @param {string} options.cacheName Name of the cache to match against.
|
742
765
|
* @param {Request} options.request The Request that will be used to look up
|
743
766
|
* cache entries.
|
744
|
-
* @param {Event} [options.event] The event that
|
767
|
+
* @param {Event} [options.event] The event that prompted the action.
|
745
768
|
* @param {Object} [options.matchOptions] Options passed to cache.match().
|
746
769
|
* @param {Array<Object>} [options.plugins=[]] Array of plugins.
|
747
770
|
* @return {Response} A cached response if available.
|
@@ -758,7 +781,7 @@ this.workbox.core = (function (exports) {
|
|
758
781
|
matchOptions,
|
759
782
|
plugins = []
|
760
783
|
}) => {
|
761
|
-
const cache = await caches.open(cacheName);
|
784
|
+
const cache = await self.caches.open(cacheName);
|
762
785
|
const effectiveRequest = await _getEffectiveRequest({
|
763
786
|
plugins,
|
764
787
|
request,
|
@@ -803,140 +826,207 @@ this.workbox.core = (function (exports) {
|
|
803
826
|
}
|
804
827
|
}
|
805
828
|
|
806
|
-
return cachedResponse;
|
829
|
+
return cachedResponse;
|
830
|
+
};
|
831
|
+
/**
|
832
|
+
* Wrapper around cache.put().
|
833
|
+
*
|
834
|
+
* Will call `cacheDidUpdate` on plugins if the cache was updated, using
|
835
|
+
* `matchOptions` when determining what the old entry is.
|
836
|
+
*
|
837
|
+
* @param {Object} options
|
838
|
+
* @param {string} options.cacheName
|
839
|
+
* @param {Request} options.request
|
840
|
+
* @param {Response} options.response
|
841
|
+
* @param {Event} [options.event]
|
842
|
+
* @param {Array<Object>} [options.plugins=[]]
|
843
|
+
* @param {Object} [options.matchOptions]
|
844
|
+
*
|
845
|
+
* @private
|
846
|
+
* @memberof module:workbox-core
|
847
|
+
*/
|
848
|
+
|
849
|
+
|
850
|
+
const putWrapper = async ({
|
851
|
+
cacheName,
|
852
|
+
request,
|
853
|
+
response,
|
854
|
+
event,
|
855
|
+
plugins = [],
|
856
|
+
matchOptions
|
857
|
+
}) => {
|
858
|
+
{
|
859
|
+
if (request.method && request.method !== 'GET') {
|
860
|
+
throw new WorkboxError('attempt-to-cache-non-get-request', {
|
861
|
+
url: getFriendlyURL(request.url),
|
862
|
+
method: request.method
|
863
|
+
});
|
864
|
+
}
|
865
|
+
}
|
866
|
+
|
867
|
+
const effectiveRequest = await _getEffectiveRequest({
|
868
|
+
plugins,
|
869
|
+
request,
|
870
|
+
mode: 'write'
|
871
|
+
});
|
872
|
+
|
873
|
+
if (!response) {
|
874
|
+
{
|
875
|
+
logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`);
|
876
|
+
}
|
877
|
+
|
878
|
+
throw new WorkboxError('cache-put-with-no-response', {
|
879
|
+
url: getFriendlyURL(effectiveRequest.url)
|
880
|
+
});
|
881
|
+
}
|
882
|
+
|
883
|
+
const responseToCache = await _isResponseSafeToCache({
|
884
|
+
event,
|
885
|
+
plugins,
|
886
|
+
response,
|
887
|
+
request: effectiveRequest
|
888
|
+
});
|
889
|
+
|
890
|
+
if (!responseToCache) {
|
891
|
+
{
|
892
|
+
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will ` + `not be cached.`, responseToCache);
|
893
|
+
}
|
894
|
+
|
895
|
+
return;
|
896
|
+
}
|
897
|
+
|
898
|
+
const cache = await self.caches.open(cacheName);
|
899
|
+
const updatePlugins = pluginUtils.filter(plugins, "cacheDidUpdate"
|
900
|
+
/* CACHE_DID_UPDATE */
|
901
|
+
);
|
902
|
+
const oldResponse = updatePlugins.length > 0 ? await matchWrapper({
|
903
|
+
cacheName,
|
904
|
+
matchOptions,
|
905
|
+
request: effectiveRequest
|
906
|
+
}) : null;
|
907
|
+
|
908
|
+
{
|
909
|
+
logger.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(effectiveRequest.url)}.`);
|
910
|
+
}
|
911
|
+
|
912
|
+
try {
|
913
|
+
await cache.put(effectiveRequest, responseToCache);
|
914
|
+
} catch (error) {
|
915
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError
|
916
|
+
if (error.name === 'QuotaExceededError') {
|
917
|
+
await executeQuotaErrorCallbacks();
|
918
|
+
}
|
919
|
+
|
920
|
+
throw error;
|
921
|
+
}
|
922
|
+
|
923
|
+
for (const plugin of updatePlugins) {
|
924
|
+
await plugin["cacheDidUpdate"
|
925
|
+
/* CACHE_DID_UPDATE */
|
926
|
+
].call(plugin, {
|
927
|
+
cacheName,
|
928
|
+
event,
|
929
|
+
oldResponse,
|
930
|
+
newResponse: responseToCache,
|
931
|
+
request: effectiveRequest
|
932
|
+
});
|
933
|
+
}
|
934
|
+
};
|
935
|
+
|
936
|
+
const cacheWrapper = {
|
937
|
+
put: putWrapper,
|
938
|
+
match: matchWrapper
|
807
939
|
};
|
940
|
+
|
941
|
+
/*
|
942
|
+
Copyright 2019 Google LLC
|
943
|
+
|
944
|
+
Use of this source code is governed by an MIT-style
|
945
|
+
license that can be found in the LICENSE file or at
|
946
|
+
https://opensource.org/licenses/MIT.
|
947
|
+
*/
|
948
|
+
let supportStatus;
|
808
949
|
/**
|
809
|
-
*
|
810
|
-
*
|
950
|
+
* A utility function that determines whether the current browser supports
|
951
|
+
* constructing a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
|
952
|
+
* object.
|
811
953
|
*
|
812
|
-
* @
|
813
|
-
*
|
814
|
-
* @param {Response} options.response
|
815
|
-
* @param {Event} [options.event]
|
816
|
-
* @param {Array<Object>} [options.plugins=[]]
|
817
|
-
* @return {Promise<Response>}
|
954
|
+
* @return {boolean} `true`, if the current browser can successfully
|
955
|
+
* construct a `ReadableStream`, `false` otherwise.
|
818
956
|
*
|
819
957
|
* @private
|
820
|
-
* @memberof module:workbox-core
|
821
958
|
*/
|
822
959
|
|
960
|
+
function canConstructReadableStream() {
|
961
|
+
if (supportStatus === undefined) {
|
962
|
+
// See https://github.com/GoogleChrome/workbox/issues/1473
|
963
|
+
try {
|
964
|
+
new ReadableStream({
|
965
|
+
start() {}
|
823
966
|
|
824
|
-
const _isResponseSafeToCache = async ({
|
825
|
-
request,
|
826
|
-
response,
|
827
|
-
event,
|
828
|
-
plugins = []
|
829
|
-
}) => {
|
830
|
-
let responseToCache = response;
|
831
|
-
let pluginsUsed = false;
|
832
|
-
|
833
|
-
for (let plugin of plugins) {
|
834
|
-
if ("cacheWillUpdate"
|
835
|
-
/* CACHE_WILL_UPDATE */
|
836
|
-
in plugin) {
|
837
|
-
pluginsUsed = true;
|
838
|
-
const pluginMethod = plugin["cacheWillUpdate"
|
839
|
-
/* CACHE_WILL_UPDATE */
|
840
|
-
];
|
841
|
-
responseToCache = await pluginMethod.call(plugin, {
|
842
|
-
request,
|
843
|
-
response: responseToCache,
|
844
|
-
event
|
845
967
|
});
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
finalAssertExports.isInstance(responseToCache, Response, {
|
850
|
-
moduleName: 'Plugin',
|
851
|
-
funcName: "cacheWillUpdate"
|
852
|
-
/* CACHE_WILL_UPDATE */
|
853
|
-
,
|
854
|
-
isReturnValueProblem: true
|
855
|
-
});
|
856
|
-
}
|
857
|
-
}
|
858
|
-
|
859
|
-
if (!responseToCache) {
|
860
|
-
break;
|
861
|
-
}
|
968
|
+
supportStatus = true;
|
969
|
+
} catch (error) {
|
970
|
+
supportStatus = false;
|
862
971
|
}
|
863
972
|
}
|
864
973
|
|
865
|
-
|
866
|
-
|
867
|
-
if (responseToCache) {
|
868
|
-
if (responseToCache.status !== 200) {
|
869
|
-
if (responseToCache.status === 0) {
|
870
|
-
logger.warn(`The response for '${request.url}' is an opaque ` + `response. The caching strategy that you're using will not ` + `cache opaque responses by default.`);
|
871
|
-
} else {
|
872
|
-
logger.debug(`The response for '${request.url}' returned ` + `a status code of '${response.status}' and won't be cached as a ` + `result.`);
|
873
|
-
}
|
874
|
-
}
|
875
|
-
}
|
876
|
-
}
|
974
|
+
return supportStatus;
|
975
|
+
}
|
877
976
|
|
878
|
-
|
879
|
-
|
977
|
+
/*
|
978
|
+
Copyright 2019 Google LLC
|
880
979
|
|
881
|
-
|
882
|
-
|
980
|
+
Use of this source code is governed by an MIT-style
|
981
|
+
license that can be found in the LICENSE file or at
|
982
|
+
https://opensource.org/licenses/MIT.
|
983
|
+
*/
|
984
|
+
let supportStatus$1;
|
883
985
|
/**
|
884
|
-
*
|
885
|
-
*
|
886
|
-
* returned by the last plugin is treated as the cache key for cache reads
|
887
|
-
* and/or writes.
|
986
|
+
* A utility function that determines whether the current browser supports
|
987
|
+
* constructing a new `Response` from a `response.body` stream.
|
888
988
|
*
|
889
|
-
* @
|
890
|
-
*
|
891
|
-
* @param {string} options.mode
|
892
|
-
* @param {Array<Object>} [options.plugins=[]]
|
893
|
-
* @return {Promise<Request>}
|
989
|
+
* @return {boolean} `true`, if the current browser can successfully
|
990
|
+
* construct a `Response` from a `response.body` stream, `false` otherwise.
|
894
991
|
*
|
895
992
|
* @private
|
896
|
-
* @memberof module:workbox-core
|
897
993
|
*/
|
898
994
|
|
995
|
+
function canConstructResponseFromBodyStream() {
|
996
|
+
if (supportStatus$1 === undefined) {
|
997
|
+
const testResponse = new Response('');
|
899
998
|
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
);
|
908
|
-
let effectiveRequest = request;
|
909
|
-
|
910
|
-
for (const plugin of cacheKeyWillBeUsedPlugins) {
|
911
|
-
effectiveRequest = await plugin["cacheKeyWillBeUsed"
|
912
|
-
/* CACHE_KEY_WILL_BE_USED */
|
913
|
-
].call(plugin, {
|
914
|
-
mode,
|
915
|
-
request: effectiveRequest
|
916
|
-
});
|
917
|
-
|
918
|
-
if (typeof effectiveRequest === 'string') {
|
919
|
-
effectiveRequest = new Request(effectiveRequest);
|
999
|
+
if ('body' in testResponse) {
|
1000
|
+
try {
|
1001
|
+
new Response(testResponse.body);
|
1002
|
+
supportStatus$1 = true;
|
1003
|
+
} catch (error) {
|
1004
|
+
supportStatus$1 = false;
|
1005
|
+
}
|
920
1006
|
}
|
921
1007
|
|
922
|
-
|
923
|
-
finalAssertExports.isInstance(effectiveRequest, Request, {
|
924
|
-
moduleName: 'Plugin',
|
925
|
-
funcName: "cacheKeyWillBeUsed"
|
926
|
-
/* CACHE_KEY_WILL_BE_USED */
|
927
|
-
,
|
928
|
-
isReturnValueProblem: true
|
929
|
-
});
|
930
|
-
}
|
1008
|
+
supportStatus$1 = false;
|
931
1009
|
}
|
932
1010
|
|
933
|
-
return
|
934
|
-
}
|
1011
|
+
return supportStatus$1;
|
1012
|
+
}
|
935
1013
|
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
1014
|
+
/*
|
1015
|
+
Copyright 2019 Google LLC
|
1016
|
+
Use of this source code is governed by an MIT-style
|
1017
|
+
license that can be found in the LICENSE file or at
|
1018
|
+
https://opensource.org/licenses/MIT.
|
1019
|
+
*/
|
1020
|
+
/**
|
1021
|
+
* A helper function that prevents a promise from being flagged as unused.
|
1022
|
+
*
|
1023
|
+
* @private
|
1024
|
+
**/
|
1025
|
+
|
1026
|
+
function dontWaitFor(promise) {
|
1027
|
+
// Effective no-op.
|
1028
|
+
promise.then(() => {});
|
1029
|
+
}
|
940
1030
|
|
941
1031
|
/*
|
942
1032
|
Copyright 2018 Google LLC
|
@@ -1180,7 +1270,9 @@ this.workbox.core = (function (exports) {
|
|
1180
1270
|
|
1181
1271
|
async _call(method, storeName, type, ...args) {
|
1182
1272
|
const callback = (txn, done) => {
|
1183
|
-
const objStore = txn.objectStore(storeName);
|
1273
|
+
const objStore = txn.objectStore(storeName); // TODO(philipwalton): Fix this underlying TS2684 error.
|
1274
|
+
// @ts-ignore
|
1275
|
+
|
1184
1276
|
const request = objStore[method].apply(objStore, args);
|
1185
1277
|
|
1186
1278
|
request.onsuccess = () => done(request.result);
|
@@ -1311,7 +1403,7 @@ this.workbox.core = (function (exports) {
|
|
1311
1403
|
* @param {Object} options
|
1312
1404
|
* @param {Request|string} options.request
|
1313
1405
|
* @param {Object} [options.fetchOptions]
|
1314
|
-
* @param {
|
1406
|
+
* @param {ExtendableEvent} [options.event]
|
1315
1407
|
* @param {Array<Object>} [options.plugins=[]]
|
1316
1408
|
* @return {Promise<Response>}
|
1317
1409
|
*
|
@@ -1363,7 +1455,7 @@ this.workbox.core = (function (exports) {
|
|
1363
1455
|
const originalRequest = failedFetchPlugins.length > 0 ? request.clone() : null;
|
1364
1456
|
|
1365
1457
|
try {
|
1366
|
-
for (
|
1458
|
+
for (const plugin of plugins) {
|
1367
1459
|
if ("requestWillFetch"
|
1368
1460
|
/* REQUEST_WILL_FETCH */
|
1369
1461
|
in plugin) {
|
@@ -1398,7 +1490,7 @@ this.workbox.core = (function (exports) {
|
|
1398
1490
|
// to the Request we make. Pass both to `fetchDidFail` to aid debugging.
|
1399
1491
|
|
1400
1492
|
|
1401
|
-
|
1493
|
+
const pluginFilteredRequest = request.clone();
|
1402
1494
|
|
1403
1495
|
try {
|
1404
1496
|
let fetchResponse; // See https://github.com/GoogleChrome/workbox/issues/1796
|
@@ -1464,6 +1556,80 @@ this.workbox.core = (function (exports) {
|
|
1464
1556
|
fetch: wrappedFetch
|
1465
1557
|
};
|
1466
1558
|
|
1559
|
+
/*
|
1560
|
+
Copyright 2019 Google LLC
|
1561
|
+
Use of this source code is governed by an MIT-style
|
1562
|
+
license that can be found in the LICENSE file or at
|
1563
|
+
https://opensource.org/licenses/MIT.
|
1564
|
+
*/
|
1565
|
+
/**
|
1566
|
+
* Returns a promise that resolves and the passed number of milliseconds.
|
1567
|
+
* This utility is an async/await-friendly version of `setTimeout`.
|
1568
|
+
*
|
1569
|
+
* @param {number} ms
|
1570
|
+
* @return {Promise}
|
1571
|
+
* @private
|
1572
|
+
*/
|
1573
|
+
|
1574
|
+
function timeout(ms) {
|
1575
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
1576
|
+
}
|
1577
|
+
|
1578
|
+
/*
|
1579
|
+
Copyright 2019 Google LLC
|
1580
|
+
Use of this source code is governed by an MIT-style
|
1581
|
+
license that can be found in the LICENSE file or at
|
1582
|
+
https://opensource.org/licenses/MIT.
|
1583
|
+
*/
|
1584
|
+
const MAX_RETRY_TIME = 2000;
|
1585
|
+
/**
|
1586
|
+
* Returns a promise that resolves to a window client matching the passed
|
1587
|
+
* `resultingClientId`. For browsers that don't support `resultingClientId`
|
1588
|
+
* or if waiting for the resulting client to apper takes too long, resolve to
|
1589
|
+
* `undefined`.
|
1590
|
+
*
|
1591
|
+
* @param {string} [resultingClientId]
|
1592
|
+
* @return {Promise<Client|undefined>}
|
1593
|
+
* @private
|
1594
|
+
*/
|
1595
|
+
|
1596
|
+
async function resultingClientExists(resultingClientId) {
|
1597
|
+
if (!resultingClientId) {
|
1598
|
+
return;
|
1599
|
+
}
|
1600
|
+
|
1601
|
+
let existingWindows = await self.clients.matchAll({
|
1602
|
+
type: 'window'
|
1603
|
+
});
|
1604
|
+
const existingWindowIds = new Set(existingWindows.map(w => w.id));
|
1605
|
+
let resultingWindow;
|
1606
|
+
const startTime = performance.now(); // Only wait up to `MAX_RETRY_TIME` to find a matching client.
|
1607
|
+
|
1608
|
+
while (performance.now() - startTime < MAX_RETRY_TIME) {
|
1609
|
+
existingWindows = await self.clients.matchAll({
|
1610
|
+
type: 'window'
|
1611
|
+
});
|
1612
|
+
resultingWindow = existingWindows.find(w => {
|
1613
|
+
if (resultingClientId) {
|
1614
|
+
// If we have a `resultingClientId`, we can match on that.
|
1615
|
+
return w.id === resultingClientId;
|
1616
|
+
} else {
|
1617
|
+
// Otherwise match on finding a window not in `existingWindowIds`.
|
1618
|
+
return !existingWindowIds.has(w.id);
|
1619
|
+
}
|
1620
|
+
});
|
1621
|
+
|
1622
|
+
if (resultingWindow) {
|
1623
|
+
break;
|
1624
|
+
} // Sleep for 100ms and retry.
|
1625
|
+
|
1626
|
+
|
1627
|
+
await timeout(100);
|
1628
|
+
}
|
1629
|
+
|
1630
|
+
return resultingWindow;
|
1631
|
+
}
|
1632
|
+
|
1467
1633
|
/*
|
1468
1634
|
Copyright 2018 Google LLC
|
1469
1635
|
|
@@ -1473,9 +1639,13 @@ this.workbox.core = (function (exports) {
|
|
1473
1639
|
*/
|
1474
1640
|
|
1475
1641
|
var _private = /*#__PURE__*/Object.freeze({
|
1642
|
+
__proto__: null,
|
1476
1643
|
assert: finalAssertExports,
|
1477
1644
|
cacheNames: cacheNames,
|
1478
1645
|
cacheWrapper: cacheWrapper,
|
1646
|
+
canConstructReadableStream: canConstructReadableStream,
|
1647
|
+
canConstructResponseFromBodyStream: canConstructResponseFromBodyStream,
|
1648
|
+
dontWaitFor: dontWaitFor,
|
1479
1649
|
DBWrapper: DBWrapper,
|
1480
1650
|
Deferred: Deferred,
|
1481
1651
|
deleteDatabase: deleteDatabase,
|
@@ -1483,27 +1653,11 @@ this.workbox.core = (function (exports) {
|
|
1483
1653
|
fetchWrapper: fetchWrapper,
|
1484
1654
|
getFriendlyURL: getFriendlyURL,
|
1485
1655
|
logger: logger,
|
1656
|
+
resultingClientExists: resultingClientExists,
|
1657
|
+
timeout: timeout,
|
1486
1658
|
WorkboxError: WorkboxError
|
1487
1659
|
});
|
1488
1660
|
|
1489
|
-
/*
|
1490
|
-
Copyright 2019 Google LLC
|
1491
|
-
|
1492
|
-
Use of this source code is governed by an MIT-style
|
1493
|
-
license that can be found in the LICENSE file or at
|
1494
|
-
https://opensource.org/licenses/MIT.
|
1495
|
-
*/
|
1496
|
-
/**
|
1497
|
-
* Claim any currently available clients once the service worker
|
1498
|
-
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
1499
|
-
*
|
1500
|
-
* @alias workbox.core.clientsClaim
|
1501
|
-
*/
|
1502
|
-
|
1503
|
-
const clientsClaim = () => {
|
1504
|
-
addEventListener('activate', () => self.clients.claim());
|
1505
|
-
};
|
1506
|
-
|
1507
1661
|
/*
|
1508
1662
|
Copyright 2019 Google LLC
|
1509
1663
|
|
@@ -1524,7 +1678,7 @@ this.workbox.core = (function (exports) {
|
|
1524
1678
|
* @return {Object} An object with `precache`, `runtime`, `prefix`, and
|
1525
1679
|
* `googleAnalytics` properties.
|
1526
1680
|
*
|
1527
|
-
* @
|
1681
|
+
* @memberof module:workbox-core
|
1528
1682
|
*/
|
1529
1683
|
|
1530
1684
|
const cacheNames$1 = {
|
@@ -1550,6 +1704,65 @@ this.workbox.core = (function (exports) {
|
|
1550
1704
|
|
1551
1705
|
};
|
1552
1706
|
|
1707
|
+
/*
|
1708
|
+
Copyright 2019 Google LLC
|
1709
|
+
|
1710
|
+
Use of this source code is governed by an MIT-style
|
1711
|
+
license that can be found in the LICENSE file or at
|
1712
|
+
https://opensource.org/licenses/MIT.
|
1713
|
+
*/
|
1714
|
+
/**
|
1715
|
+
* Allows developers to copy a response and modify its `headers`, `status`,
|
1716
|
+
* or `statusText` values (the values settable via a
|
1717
|
+
* [`ResponseInit`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#Syntax}
|
1718
|
+
* object in the constructor).
|
1719
|
+
* To modify these values, pass a function as the second argument. That
|
1720
|
+
* function will be invoked with a single object with the response properties
|
1721
|
+
* `{headers, status, statusText}`. The return value of this function will
|
1722
|
+
* be used as the `ResponseInit` for the new `Response`. To change the values
|
1723
|
+
* either modify the passed parameter(s) and return it, or return a totally
|
1724
|
+
* new object.
|
1725
|
+
*
|
1726
|
+
* @param {Response} response
|
1727
|
+
* @param {Function} modifier
|
1728
|
+
* @memberof module:workbox-core
|
1729
|
+
*/
|
1730
|
+
|
1731
|
+
async function copyResponse(response, modifier) {
|
1732
|
+
const clonedResponse = response.clone(); // Create a fresh `ResponseInit` object by cloning the headers.
|
1733
|
+
|
1734
|
+
const responseInit = {
|
1735
|
+
headers: new Headers(clonedResponse.headers),
|
1736
|
+
status: clonedResponse.status,
|
1737
|
+
statusText: clonedResponse.statusText
|
1738
|
+
}; // Apply any user modifications.
|
1739
|
+
|
1740
|
+
const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit; // Create the new response from the body stream and `ResponseInit`
|
1741
|
+
// modifications. Note: not all browsers support the Response.body stream,
|
1742
|
+
// so fall back to reading the entire body into memory as a blob.
|
1743
|
+
|
1744
|
+
const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
|
1745
|
+
return new Response(body, modifiedResponseInit);
|
1746
|
+
}
|
1747
|
+
|
1748
|
+
/*
|
1749
|
+
Copyright 2019 Google LLC
|
1750
|
+
|
1751
|
+
Use of this source code is governed by an MIT-style
|
1752
|
+
license that can be found in the LICENSE file or at
|
1753
|
+
https://opensource.org/licenses/MIT.
|
1754
|
+
*/
|
1755
|
+
/**
|
1756
|
+
* Claim any currently available clients once the service worker
|
1757
|
+
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
1758
|
+
*
|
1759
|
+
* @memberof module:workbox-core
|
1760
|
+
*/
|
1761
|
+
|
1762
|
+
function clientsClaim() {
|
1763
|
+
self.addEventListener('activate', () => self.clients.claim());
|
1764
|
+
}
|
1765
|
+
|
1553
1766
|
/*
|
1554
1767
|
Copyright 2019 Google LLC
|
1555
1768
|
|
@@ -1572,10 +1785,10 @@ this.workbox.core = (function (exports) {
|
|
1572
1785
|
* @param {Object} [details.googleAnalytics] The cache name to use for
|
1573
1786
|
* `workbox-google-analytics` caching.
|
1574
1787
|
*
|
1575
|
-
* @
|
1788
|
+
* @memberof module:workbox-core
|
1576
1789
|
*/
|
1577
1790
|
|
1578
|
-
|
1791
|
+
function setCacheNameDetails(details) {
|
1579
1792
|
{
|
1580
1793
|
Object.keys(details).forEach(key => {
|
1581
1794
|
finalAssertExports.isType(details[key], 'string', {
|
@@ -1585,30 +1798,30 @@ this.workbox.core = (function (exports) {
|
|
1585
1798
|
});
|
1586
1799
|
});
|
1587
1800
|
|
1588
|
-
if ('precache' in details && details
|
1801
|
+
if ('precache' in details && details['precache'].length === 0) {
|
1589
1802
|
throw new WorkboxError('invalid-cache-name', {
|
1590
1803
|
cacheNameId: 'precache',
|
1591
|
-
value: details
|
1804
|
+
value: details['precache']
|
1592
1805
|
});
|
1593
1806
|
}
|
1594
1807
|
|
1595
|
-
if ('runtime' in details && details
|
1808
|
+
if ('runtime' in details && details['runtime'].length === 0) {
|
1596
1809
|
throw new WorkboxError('invalid-cache-name', {
|
1597
1810
|
cacheNameId: 'runtime',
|
1598
|
-
value: details
|
1811
|
+
value: details['runtime']
|
1599
1812
|
});
|
1600
1813
|
}
|
1601
1814
|
|
1602
|
-
if ('googleAnalytics' in details && details
|
1815
|
+
if ('googleAnalytics' in details && details['googleAnalytics'].length === 0) {
|
1603
1816
|
throw new WorkboxError('invalid-cache-name', {
|
1604
1817
|
cacheNameId: 'googleAnalytics',
|
1605
|
-
value: details
|
1818
|
+
value: details['googleAnalytics']
|
1606
1819
|
});
|
1607
1820
|
}
|
1608
1821
|
}
|
1609
1822
|
|
1610
1823
|
cacheNames.updateDetails(details);
|
1611
|
-
}
|
1824
|
+
}
|
1612
1825
|
|
1613
1826
|
/*
|
1614
1827
|
Copyright 2019 Google LLC
|
@@ -1618,21 +1831,23 @@ this.workbox.core = (function (exports) {
|
|
1618
1831
|
https://opensource.org/licenses/MIT.
|
1619
1832
|
*/
|
1620
1833
|
/**
|
1621
|
-
* Force a service worker to
|
1622
|
-
*
|
1834
|
+
* Force a service worker to activate immediately, instead of
|
1835
|
+
* [waiting](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting)
|
1836
|
+
* for existing clients to close.
|
1623
1837
|
*
|
1624
|
-
* @
|
1838
|
+
* @memberof module:workbox-core
|
1625
1839
|
*/
|
1626
1840
|
|
1627
|
-
|
1841
|
+
function skipWaiting() {
|
1628
1842
|
// We need to explicitly call `self.skipWaiting()` here because we're
|
1629
1843
|
// shadowing `skipWaiting` with this local function.
|
1630
|
-
addEventListener('install', () => self.skipWaiting());
|
1631
|
-
}
|
1844
|
+
self.addEventListener('install', () => self.skipWaiting());
|
1845
|
+
}
|
1632
1846
|
|
1633
1847
|
exports._private = _private;
|
1634
1848
|
exports.cacheNames = cacheNames$1;
|
1635
1849
|
exports.clientsClaim = clientsClaim;
|
1850
|
+
exports.copyResponse = copyResponse;
|
1636
1851
|
exports.registerQuotaErrorCallback = registerQuotaErrorCallback;
|
1637
1852
|
exports.setCacheNameDetails = setCacheNameDetails;
|
1638
1853
|
exports.skipWaiting = skipWaiting;
|