workbox-precaching
Advanced tools
Comparing version 7.0.0 to 7.1.0
@@ -5,2 +5,3 @@ this.workbox = this.workbox || {}; | ||
// @ts-ignore | ||
try { | ||
@@ -17,3 +18,3 @@ self['workbox:precaching:7.0.0'] && _(); | ||
*/ | ||
// Name of the search parameter used to store revision info. | ||
const REVISION_SEARCH_PARAM = '__WB_REVISION__'; | ||
@@ -29,3 +30,2 @@ /** | ||
*/ | ||
function createCacheKey(entry) { | ||
@@ -36,6 +36,5 @@ if (!entry) { | ||
}); | ||
} // If a precache manifest entry is a string, it's assumed to be a versioned | ||
} | ||
// If a precache manifest entry is a string, it's assumed to be a versioned | ||
// URL, like '/app.abcd1234.js'. Return as-is. | ||
if (typeof entry === 'string') { | ||
@@ -48,3 +47,2 @@ const urlObject = new URL(entry, location.href); | ||
} | ||
const { | ||
@@ -54,3 +52,2 @@ revision, | ||
} = entry; | ||
if (!url) { | ||
@@ -60,6 +57,5 @@ throw new WorkboxError_js.WorkboxError('add-to-cache-list-unexpected-type', { | ||
}); | ||
} // If there's just a URL and no revision, then it's also assumed to be a | ||
} | ||
// If there's just a URL and no revision, then it's also assumed to be a | ||
// versioned URL. | ||
if (!revision) { | ||
@@ -71,6 +67,5 @@ const urlObject = new URL(url, location.href); | ||
}; | ||
} // Otherwise, construct a properly versioned URL using the custom Workbox | ||
} | ||
// Otherwise, construct a properly versioned URL using the custom Workbox | ||
// search parameter along with the revision info. | ||
const cacheKeyURL = new URL(url, location.href); | ||
@@ -98,3 +93,2 @@ const originalURL = new URL(url, location.href); | ||
*/ | ||
class PrecacheInstallReportPlugin { | ||
@@ -104,3 +98,2 @@ constructor() { | ||
this.notUpdatedURLs = []; | ||
this.handlerWillStart = async ({ | ||
@@ -115,3 +108,2 @@ request, | ||
}; | ||
this.cachedResponseWillBeUsed = async ({ | ||
@@ -126,3 +118,2 @@ event, | ||
const url = state.originalRequest.url; | ||
if (cachedResponse) { | ||
@@ -135,7 +126,5 @@ this.notUpdatedURLs.push(url); | ||
} | ||
return cachedResponse; | ||
}; | ||
} | ||
} | ||
@@ -156,3 +145,2 @@ | ||
*/ | ||
class PrecacheCacheKeyPlugin { | ||
@@ -167,8 +155,5 @@ constructor({ | ||
// Params is type any, can't change right now. | ||
/* eslint-disable */ | ||
const cacheKey = (params === null || params === void 0 ? void 0 : params.cacheKey) || this._precacheController.getCacheKeyForURL(request.url); | ||
/* eslint-enable */ | ||
return cacheKey ? new Request(cacheKey, { | ||
@@ -178,6 +163,4 @@ headers: request.headers | ||
}; | ||
this._precacheController = precacheController; | ||
} | ||
} | ||
@@ -198,10 +181,7 @@ | ||
*/ | ||
const logGroup = (groupTitle, deletedURLs) => { | ||
logger_js.logger.groupCollapsed(groupTitle); | ||
for (const url of deletedURLs) { | ||
logger_js.logger.log(url); | ||
} | ||
logger_js.logger.groupEnd(); | ||
@@ -215,7 +195,4 @@ }; | ||
*/ | ||
function printCleanupDetails(deletedURLs) { | ||
const deletionCount = deletedURLs.length; | ||
if (deletionCount > 0) { | ||
@@ -241,3 +218,2 @@ logger_js.logger.groupCollapsed(`During precaching cleanup, ` + `${deletionCount} cached ` + `request${deletionCount === 1 ? ' was' : 's were'} deleted.`); | ||
*/ | ||
function _nestedGroup(groupTitle, urls) { | ||
@@ -247,9 +223,6 @@ if (urls.length === 0) { | ||
} | ||
logger_js.logger.groupCollapsed(groupTitle); | ||
for (const url of urls) { | ||
logger_js.logger.log(url); | ||
} | ||
logger_js.logger.groupEnd(); | ||
@@ -264,21 +237,13 @@ } | ||
*/ | ||
function printInstallDetails(urlsToPrecache, urlsAlreadyPrecached) { | ||
const precachedCount = urlsToPrecache.length; | ||
const alreadyPrecachedCount = urlsAlreadyPrecached.length; | ||
if (precachedCount || alreadyPrecachedCount) { | ||
let message = `Precaching ${precachedCount} file${precachedCount === 1 ? '' : 's'}.`; | ||
if (alreadyPrecachedCount > 0) { | ||
message += ` ${alreadyPrecachedCount} ` + `file${alreadyPrecachedCount === 1 ? ' is' : 's are'} already cached.`; | ||
} | ||
logger_js.logger.groupCollapsed(message); | ||
_nestedGroup(`View newly precached URLs.`, urlsToPrecache); | ||
_nestedGroup(`View previously precached URLs.`, urlsAlreadyPrecached); | ||
logger_js.logger.groupEnd(); | ||
@@ -307,3 +272,2 @@ } | ||
*/ | ||
class PrecacheStrategy extends Strategy_js.Strategy { | ||
@@ -330,7 +294,7 @@ /** | ||
super(options); | ||
this._fallbackToNetwork = options.fallbackToNetwork === false ? false : true; // Redirected responses cannot be used to satisfy a navigation request, so | ||
this._fallbackToNetwork = options.fallbackToNetwork === false ? false : true; | ||
// Redirected responses cannot be used to satisfy a navigation request, so | ||
// any redirected response must be "copied" rather than cloned, so the new | ||
// response doesn't contain the `redirected` flag. See: | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=669363&desc=2#c1 | ||
this.plugins.push(PrecacheStrategy.copyRedirectedCacheableResponsesPlugin); | ||
@@ -345,26 +309,20 @@ } | ||
*/ | ||
async _handle(request, handler) { | ||
const response = await handler.cacheMatch(request); | ||
if (response) { | ||
return response; | ||
} // If this is an `install` event for an entry that isn't already cached, | ||
} | ||
// If this is an `install` event for an entry that isn't already cached, | ||
// then populate the cache. | ||
if (handler.event && handler.event.type === 'install') { | ||
return await this._handleInstall(request, handler); | ||
} // Getting here means something went wrong. An entry that should have been | ||
} | ||
// Getting here means something went wrong. An entry that should have been | ||
// precached wasn't found in the cache. | ||
return await this._handleFetch(request, handler); | ||
} | ||
async _handleFetch(request, handler) { | ||
let response; | ||
const params = handler.params || {}; // Fall back to the network if we're configured to do so. | ||
const params = handler.params || {}; | ||
// Fall back to the network if we're configured to do so. | ||
if (this._fallbackToNetwork) { | ||
@@ -374,11 +332,11 @@ { | ||
} | ||
const integrityInManifest = params.integrity; | ||
const integrityInRequest = request.integrity; | ||
const noIntegrityConflict = !integrityInRequest || integrityInRequest === integrityInManifest; // Do not add integrity if the original request is no-cors | ||
const noIntegrityConflict = !integrityInRequest || integrityInRequest === integrityInManifest; | ||
// Do not add integrity if the original request is no-cors | ||
// See https://github.com/GoogleChrome/workbox/issues/3096 | ||
response = await handler.fetch(new Request(request, { | ||
integrity: request.mode !== 'no-cors' ? integrityInRequest || integrityInManifest : undefined | ||
})); // It's only "safe" to repair the cache if we're using SRI to guarantee | ||
})); | ||
// It's only "safe" to repair the cache if we're using SRI to guarantee | ||
// that the response matches the precache manifest's expectations, | ||
@@ -390,8 +348,5 @@ // and there's either a) no integrity property in the incoming request | ||
// See https://github.com/GoogleChrome/workbox/issues/3096 | ||
if (integrityInManifest && noIntegrityConflict && request.mode !== 'no-cors') { | ||
this._useDefaultCacheabilityPluginIfNeeded(); | ||
const wasCached = await handler.cachePut(request, response.clone()); | ||
{ | ||
@@ -411,7 +366,6 @@ if (wasCached) { | ||
} | ||
{ | ||
const cacheKey = params.cacheKey || (await handler.getCacheKey(request, 'read')); // Workbox is going to handle the route. | ||
const cacheKey = params.cacheKey || (await handler.getCacheKey(request, 'read')); | ||
// Workbox is going to handle the route. | ||
// print the routing details to the console. | ||
logger_js.logger.groupCollapsed(`Precaching is responding to: ` + getFriendlyURL_js.getFriendlyURL(request.url)); | ||
@@ -427,14 +381,10 @@ logger_js.logger.log(`Serving the precached url: ${getFriendlyURL_js.getFriendlyURL(cacheKey instanceof Request ? cacheKey.url : cacheKey)}`); | ||
} | ||
return response; | ||
} | ||
async _handleInstall(request, handler) { | ||
this._useDefaultCacheabilityPluginIfNeeded(); | ||
const response = await handler.fetch(request); // Make sure we defer cachePut() until after we know the response | ||
const response = await handler.fetch(request); | ||
// Make sure we defer cachePut() until after we know the response | ||
// should be cached; see https://github.com/GoogleChrome/workbox/issues/2737 | ||
const wasCached = await handler.cachePut(request, response.clone()); | ||
if (!wasCached) { | ||
@@ -448,3 +398,2 @@ // Throwing here will lead to the `install` handler failing, which | ||
} | ||
return response; | ||
@@ -479,8 +428,5 @@ } | ||
*/ | ||
_useDefaultCacheabilityPluginIfNeeded() { | ||
let defaultPluginIndex = null; | ||
let cacheWillUpdatePluginCount = 0; | ||
for (const [index, plugin] of this.plugins.entries()) { | ||
@@ -490,9 +436,7 @@ // Ignore the copy redirected plugin when determining what to do. | ||
continue; | ||
} // Save the default plugin's index, in case it needs to be removed. | ||
} | ||
// Save the default plugin's index, in case it needs to be removed. | ||
if (plugin === PrecacheStrategy.defaultPrecacheCacheabilityPlugin) { | ||
defaultPluginIndex = index; | ||
} | ||
if (plugin.cacheWillUpdate) { | ||
@@ -502,3 +446,2 @@ cacheWillUpdatePluginCount++; | ||
} | ||
if (cacheWillUpdatePluginCount === 0) { | ||
@@ -509,8 +452,6 @@ this.plugins.push(PrecacheStrategy.defaultPrecacheCacheabilityPlugin); | ||
this.plugins.splice(defaultPluginIndex, 1); | ||
} // Nothing needs to be done if cacheWillUpdatePluginCount is 1 | ||
} | ||
// Nothing needs to be done if cacheWillUpdatePluginCount is 1 | ||
} | ||
} | ||
PrecacheStrategy.defaultPrecacheCacheabilityPlugin = { | ||
@@ -523,6 +464,4 @@ async cacheWillUpdate({ | ||
} | ||
return response; | ||
} | ||
}; | ||
@@ -535,3 +474,2 @@ PrecacheStrategy.copyRedirectedCacheableResponsesPlugin = { | ||
} | ||
}; | ||
@@ -551,3 +489,2 @@ | ||
*/ | ||
class PrecacheController { | ||
@@ -578,4 +515,4 @@ /** | ||
fallbackToNetwork | ||
}); // Bind the install and activate methods to the instance. | ||
}); | ||
// Bind the install and activate methods to the instance. | ||
this.install = this.install.bind(this); | ||
@@ -588,4 +525,2 @@ this.activate = this.activate.bind(this); | ||
*/ | ||
get strategy() { | ||
@@ -604,7 +539,4 @@ return this._strategy; | ||
*/ | ||
precache(entries) { | ||
this.addToCacheList(entries); | ||
if (!this._installAndActiveListenersAdded) { | ||
@@ -623,4 +555,2 @@ self.addEventListener('install', this.install); | ||
*/ | ||
addToCacheList(entries) { | ||
@@ -635,5 +565,3 @@ { | ||
} | ||
const urlsToWarnAbout = []; | ||
for (const entry of entries) { | ||
@@ -646,3 +574,2 @@ // See https://github.com/GoogleChrome/workbox/issues/2259 | ||
} | ||
const { | ||
@@ -653,3 +580,2 @@ cacheKey, | ||
const cacheMode = typeof entry !== 'string' && entry.revision ? 'reload' : 'default'; | ||
if (this._urlsToCacheKeys.has(url) && this._urlsToCacheKeys.get(url) !== cacheKey) { | ||
@@ -661,3 +587,2 @@ throw new WorkboxError_js.WorkboxError('add-to-cache-list-conflicting-entries', { | ||
} | ||
if (typeof entry !== 'string' && entry.integrity) { | ||
@@ -669,13 +594,8 @@ if (this._cacheKeysToIntegrities.has(cacheKey) && this._cacheKeysToIntegrities.get(cacheKey) !== entry.integrity) { | ||
} | ||
this._cacheKeysToIntegrities.set(cacheKey, entry.integrity); | ||
} | ||
this._urlsToCacheKeys.set(url, cacheKey); | ||
this._urlsToCacheModes.set(url, cacheMode); | ||
if (urlsToWarnAbout.length > 0) { | ||
const warningMessage = `Workbox is precaching URLs without revision ` + `info: ${urlsToWarnAbout.join(', ')}\nThis is generally NOT safe. ` + `Learn more at https://bit.ly/wb-precache`; | ||
{ | ||
@@ -697,4 +617,2 @@ logger_js.logger.warn(warningMessage); | ||
*/ | ||
install(event) { | ||
@@ -705,10 +623,8 @@ // waitUntil returns Promise<any> | ||
const installReportPlugin = new PrecacheInstallReportPlugin(); | ||
this.strategy.plugins.push(installReportPlugin); // Cache entries one at a time. | ||
this.strategy.plugins.push(installReportPlugin); | ||
// Cache entries one at a time. | ||
// See https://github.com/GoogleChrome/workbox/issues/2528 | ||
for (const [url, cacheKey] of this._urlsToCacheKeys) { | ||
const integrity = this._cacheKeysToIntegrities.get(cacheKey); | ||
const cacheMode = this._urlsToCacheModes.get(url); | ||
const request = new Request(url, { | ||
@@ -727,3 +643,2 @@ integrity, | ||
} | ||
const { | ||
@@ -733,7 +648,5 @@ updatedURLs, | ||
} = installReportPlugin; | ||
{ | ||
printInstallDetails(updatedURLs, notUpdatedURLs); | ||
} | ||
return { | ||
@@ -755,4 +668,2 @@ updatedURLs, | ||
*/ | ||
activate(event) { | ||
@@ -766,3 +677,2 @@ // waitUntil returns Promise<any> | ||
const deletedURLs = []; | ||
for (const request of currentlyCachedRequests) { | ||
@@ -774,7 +684,5 @@ if (!expectedCacheKeys.has(request.url)) { | ||
} | ||
{ | ||
printCleanupDetails(deletedURLs); | ||
} | ||
return { | ||
@@ -791,4 +699,2 @@ deletedURLs | ||
*/ | ||
getURLsToCacheKeys() { | ||
@@ -803,4 +709,2 @@ return this._urlsToCacheKeys; | ||
*/ | ||
getCachedURLs() { | ||
@@ -818,4 +722,2 @@ return [...this._urlsToCacheKeys.keys()]; | ||
*/ | ||
getCacheKeyForURL(url) { | ||
@@ -830,4 +732,2 @@ const urlObject = new URL(url, location.href); | ||
*/ | ||
getIntegrityForCacheKey(cacheKey) { | ||
@@ -854,8 +754,5 @@ return this._cacheKeysToIntegrities.get(cacheKey); | ||
*/ | ||
async matchPrecache(request) { | ||
const url = request instanceof Request ? request.url : request; | ||
const cacheKey = this.getCacheKeyForURL(url); | ||
if (cacheKey) { | ||
@@ -865,3 +762,2 @@ const cache = await self.caches.open(this.strategy.cacheName); | ||
} | ||
return undefined; | ||
@@ -877,7 +773,4 @@ } | ||
*/ | ||
createHandlerBoundToURL(url) { | ||
const cacheKey = this.getCacheKeyForURL(url); | ||
if (!cacheKey) { | ||
@@ -888,3 +781,2 @@ throw new WorkboxError_js.WorkboxError('non-precached-url', { | ||
} | ||
return options => { | ||
@@ -898,3 +790,2 @@ options.request = new Request(url); | ||
} | ||
} | ||
@@ -914,3 +805,2 @@ | ||
*/ | ||
const getOrCreatePrecacheController = () => { | ||
@@ -920,3 +810,2 @@ if (!precacheController) { | ||
} | ||
return precacheController; | ||
@@ -939,3 +828,2 @@ }; | ||
*/ | ||
function addPlugins(plugins) { | ||
@@ -965,3 +853,2 @@ const precacheController = getOrCreatePrecacheController(); | ||
*/ | ||
function removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching = []) { | ||
@@ -975,3 +862,2 @@ // Convert the iterable into an array at the start of the loop to make sure | ||
} | ||
return urlObject; | ||
@@ -997,3 +883,2 @@ } | ||
*/ | ||
function* generateURLVariations(url, { | ||
@@ -1010,3 +895,2 @@ ignoreURLParametersMatching = [/^utm_/, /^fbclid$/], | ||
yield urlWithoutIgnoredParams.href; | ||
if (directoryIndex && urlWithoutIgnoredParams.pathname.endsWith('/')) { | ||
@@ -1017,3 +901,2 @@ const directoryURL = new URL(urlWithoutIgnoredParams.href); | ||
} | ||
if (cleanURLs) { | ||
@@ -1024,3 +907,2 @@ const cleanURL = new URL(urlWithoutIgnoredParams.href); | ||
} | ||
if (urlManipulation) { | ||
@@ -1030,3 +912,2 @@ const additionalURLs = urlManipulation({ | ||
}); | ||
for (const urlToAttempt of additionalURLs) { | ||
@@ -1054,3 +935,2 @@ yield urlToAttempt.href; | ||
*/ | ||
class PrecacheRoute extends Route_js.Route { | ||
@@ -1078,6 +958,4 @@ /** | ||
const urlsToCacheKeys = precacheController.getURLsToCacheKeys(); | ||
for (const possibleURL of generateURLVariations(request.url, options)) { | ||
const cacheKey = urlsToCacheKeys.get(possibleURL); | ||
if (cacheKey) { | ||
@@ -1091,13 +969,9 @@ const integrity = precacheController.getIntegrityForCacheKey(cacheKey); | ||
} | ||
{ | ||
logger_js.logger.debug(`Precaching did not find a match for ` + getFriendlyURL_js.getFriendlyURL(request.url)); | ||
} | ||
return; | ||
}; | ||
super(match, precacheController.strategy); | ||
} | ||
} | ||
@@ -1126,3 +1000,2 @@ | ||
*/ | ||
function addRoute(options) { | ||
@@ -1160,3 +1033,2 @@ const precacheController = getOrCreatePrecacheController(); | ||
*/ | ||
const deleteOutdatedCaches = async (currentPrecacheName, substringToFind = SUBSTRING_TO_FIND) => { | ||
@@ -1184,3 +1056,2 @@ const cacheNames = await self.caches.keys(); | ||
*/ | ||
function cleanupOutdatedCaches() { | ||
@@ -1224,3 +1095,2 @@ // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705 | ||
*/ | ||
function createHandlerBoundToURL(url) { | ||
@@ -1257,3 +1127,2 @@ const precacheController = getOrCreatePrecacheController(); | ||
*/ | ||
function getCacheKeyForURL(url) { | ||
@@ -1286,3 +1155,2 @@ const precacheController = getOrCreatePrecacheController(); | ||
*/ | ||
function matchPrecache(request) { | ||
@@ -1319,3 +1187,2 @@ const precacheController = getOrCreatePrecacheController(); | ||
*/ | ||
function precache(entries) { | ||
@@ -1347,3 +1214,2 @@ const precacheController = getOrCreatePrecacheController(); | ||
*/ | ||
function precacheAndRoute(entries, options) { | ||
@@ -1375,3 +1241,2 @@ precache(entries); | ||
*/ | ||
class PrecacheFallbackPlugin { | ||
@@ -1398,7 +1263,5 @@ /** | ||
this.handlerDidError = () => this._precacheController.matchPrecache(this._fallbackURL); | ||
this._fallbackURL = fallbackURL; | ||
this._precacheController = precacheController || getOrCreatePrecacheController(); | ||
} | ||
} | ||
@@ -1421,3 +1284,3 @@ | ||
}({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core, workbox.core._private, workbox.strategies, workbox.routing, workbox.routing)); | ||
})({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core, workbox.core._private, workbox.strategies, workbox.routing, workbox.routing); | ||
//# sourceMappingURL=workbox-precaching.dev.js.map |
{ | ||
"name": "workbox-precaching", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"license": "MIT", | ||
@@ -24,7 +24,7 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "7.0.0", | ||
"workbox-routing": "7.0.0", | ||
"workbox-strategies": "7.0.0" | ||
"workbox-core": "7.1.0", | ||
"workbox-routing": "7.1.0", | ||
"workbox-strategies": "7.1.0" | ||
}, | ||
"gitHead": "c1d11636823e5e3a89520f7a531970a39304b14a" | ||
"gitHead": "9e69c4269c35e2db9fbba4d13e4e6206c7b66d2a" | ||
} |
// @ts-ignore | ||
try{self['workbox:precaching:7.0.0']&&_()}catch(e){} | ||
try{self['workbox:precaching:7.1.0']&&_()}catch(e){} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 3 instances in 1 package
356800
4664
+ Addedworkbox-core@7.1.0(transitive)
+ Addedworkbox-routing@7.1.0(transitive)
+ Addedworkbox-strategies@7.1.0(transitive)
- Removedworkbox-core@7.0.0(transitive)
- Removedworkbox-routing@7.0.0(transitive)
- Removedworkbox-strategies@7.0.0(transitive)
Updatedworkbox-core@7.1.0
Updatedworkbox-routing@7.1.0
Updatedworkbox-strategies@7.1.0