workbox-precaching
Advanced tools
Comparing version 3.0.0-alpha.3 to 3.0.0-alpha.4
@@ -6,3 +6,3 @@ this.workbox = this.workbox || {}; | ||
try { | ||
self.workbox.v['workbox:precaching:3.0.0-alpha.3'] = 1; | ||
self.workbox.v['workbox:precaching:3.0.0-alpha.4'] = 1; | ||
} catch (e) {} // eslint-disable-line | ||
@@ -119,12 +119,3 @@ | ||
this._db = new DBWrapper_mjs.DBWrapper(`workbox-precaching`, 2, { | ||
onupgradeneeded: evt => { | ||
if (evt.oldVersion < 2) { | ||
try { | ||
evt.target.result.deleteObjectStore('workbox-precaching'); | ||
} catch (err) { | ||
// NOOP | ||
} | ||
} | ||
evt.target.result.createObjectStore(DB_STORE_NAME); | ||
} | ||
onupgradeneeded: this._handleUpgrade | ||
}); | ||
@@ -134,2 +125,25 @@ } | ||
/** | ||
* Should perform an upgrade of indexedDB. | ||
* | ||
* @param {Event} evt | ||
* | ||
* @private | ||
*/ | ||
_handleUpgrade(evt) { | ||
const db = evt.target.result; | ||
if (evt.oldVersion < 2) { | ||
// IndexedDB version 1 used both 'workbox-precaching' and | ||
// 'precached-details-model' before upgrading to version 2. | ||
// Delete them and create a new store with latest schema. | ||
if (db.objectStoreNames.contains('workbox-precaching')) { | ||
db.deleteObjectStore('workbox-precaching'); | ||
} | ||
if (db.objectStoreNames.contains(DB_STORE_NAME)) { | ||
db.deleteObjectStore(DB_STORE_NAME); | ||
} | ||
} | ||
db.createObjectStore(DB_STORE_NAME); | ||
} | ||
/** | ||
* Check if an entry is already cached. Returns false if | ||
@@ -563,2 +577,4 @@ * the entry isn't cached or the revision has changed. | ||
* @param {boolean} options.suppressWarnings Suppress warning messages. | ||
* @param {Array<Object>} options.plugins Plugins to be used for fetching | ||
* and caching during install. | ||
* @return { | ||
@@ -575,2 +591,11 @@ * Promise<module:workbox-precaching.PrecacheController.InstallResult>} | ||
} | ||
if (options.plugins) { | ||
assert_mjs.assert.isArray(options.plugins, { | ||
moduleName: 'workbox-precaching', | ||
className: 'PrecacheController', | ||
funcName: 'install', | ||
paramName: 'plugins' | ||
}); | ||
} | ||
} | ||
@@ -591,3 +616,3 @@ | ||
yield Promise.all(entriesToPrecache.map(function (precacheEntry) { | ||
return _this._cacheEntry(precacheEntry); | ||
return _this._cacheEntry(precacheEntry, options.plugins); | ||
})); | ||
@@ -612,2 +637,4 @@ | ||
* @param {BaseCacheEntry} precacheEntry The entry to fetch and cache. | ||
* @param {Array<Object>} plugins Array of plugins to apply to fetch and | ||
* caching. | ||
* @return {Promise<boolean>} Returns a promise that resolves once the entry | ||
@@ -618,7 +645,7 @@ * has been fetched and cached or skipped if no update is needed. The | ||
*/ | ||
_cacheEntry(precacheEntry) { | ||
_cacheEntry(precacheEntry, plugins) { | ||
var _this2 = this; | ||
return babelHelpers.asyncToGenerator(function* () { | ||
let response = yield fetchWrapper_mjs.fetchWrapper.fetch(precacheEntry._networkRequest); | ||
let response = yield fetchWrapper_mjs.fetchWrapper.fetch(precacheEntry._networkRequest, null, plugins); | ||
@@ -629,3 +656,3 @@ if (response.redirected) { | ||
yield cacheWrapper_mjs.cacheWrapper.put(_this2._cacheName, precacheEntry._cacheRequest, response); | ||
yield cacheWrapper_mjs.cacheWrapper.put(_this2._cacheName, precacheEntry._cacheRequest, response, plugins); | ||
@@ -790,2 +817,3 @@ yield _this2._precacheDetailsModel._addEntry(precacheEntry); | ||
let suppressWarnings = false; | ||
let plugins = []; | ||
@@ -836,36 +864,46 @@ const cacheName = cacheNames_mjs.cacheNames.getPrecacheName(); | ||
ignoreUrlParametersMatching = [/^utm_/], | ||
directoryIndex = 'index.html' | ||
directoryIndex = 'index.html', | ||
cleanUrls = true, | ||
urlManipulation = null | ||
} = {}) => { | ||
const urlObject = new URL(url, location); | ||
// If we precache '/some-url' but the URL referenced from the browser | ||
// is '/some-url#1234', the comparison won't work unless we normalise | ||
// the URLS. | ||
// See https://github.com/GoogleChrome/workbox/issues/488. | ||
// Change '/some-url#123' => '/some-url' | ||
urlObject.hash = ''; | ||
const cachedUrls = precacheController.getCachedUrls(); | ||
if (cachedUrls.indexOf(urlObject.href) !== -1) { | ||
// It's a perfect match | ||
{ | ||
logger_mjs.logger.debug(`Precaching found an exact URL match for ` + getFriendlyURL_mjs.getFriendlyURL(urlObject.toString())); | ||
} | ||
return urlObject.href; | ||
const urlWithoutIgnoredParams = _removeIgnoreUrlParams(urlObject, ignoreUrlParametersMatching); | ||
let urlsToAttempt = [ | ||
// Test the URL that was fetched | ||
urlObject, | ||
// Test the URL without search params | ||
urlWithoutIgnoredParams]; | ||
// Test the URL with a directory index | ||
if (directoryIndex && urlWithoutIgnoredParams.pathname.endsWith('/')) { | ||
const directoryUrl = new URL(urlWithoutIgnoredParams); | ||
directoryUrl.pathname += directoryIndex; | ||
urlsToAttempt.push(directoryUrl); | ||
} | ||
let strippedUrl = _removeIgnoreUrlParams(urlObject, ignoreUrlParametersMatching); | ||
if (cachedUrls.indexOf(strippedUrl.href) !== -1) { | ||
{ | ||
logger_mjs.logger.debug(`Precaching found an exact URL match for stripped URL` + getFriendlyURL_mjs.getFriendlyURL(strippedUrl.toString())); | ||
} | ||
return strippedUrl.href; | ||
// Test the URL with a '.html' extension | ||
if (cleanUrls) { | ||
const cleanUrl = new URL(urlWithoutIgnoredParams); | ||
cleanUrl.pathname += '.html'; | ||
urlsToAttempt.push(cleanUrl); | ||
} | ||
if (directoryIndex && strippedUrl.pathname.endsWith('/')) { | ||
strippedUrl.pathname += directoryIndex; | ||
if (cachedUrls.indexOf(strippedUrl.href) !== -1) { | ||
if (urlManipulation) { | ||
const additionalUrls = urlManipulation({ url: urlObject }); | ||
urlsToAttempt = urlsToAttempt.concat(additionalUrls); | ||
} | ||
const cachedUrls = precacheController.getCachedUrls(); | ||
for (const possibleUrl of urlsToAttempt) { | ||
if (cachedUrls.indexOf(possibleUrl.href) !== -1) { | ||
// It's a perfect match | ||
{ | ||
logger_mjs.logger.debug(`Precaching found an exact URL match with ` + `'directoryIndex' ${getFriendlyURL_mjs.getFriendlyURL(strippedUrl.toString())}`); | ||
logger_mjs.logger.debug(`Precaching found a match for ` + getFriendlyURL_mjs.getFriendlyURL(possibleUrl.toString())); | ||
} | ||
return strippedUrl.href; | ||
return possibleUrl.href; | ||
} | ||
@@ -907,3 +945,6 @@ } | ||
self.addEventListener('install', event => { | ||
event.waitUntil(precacheController.install({ suppressWarnings })); | ||
event.waitUntil(precacheController.install({ | ||
suppressWarnings, | ||
plugins | ||
})); | ||
}); | ||
@@ -931,2 +972,7 @@ self.addEventListener('activate', event => { | ||
* array of regex's to remove search params when looking for a cache match. | ||
* @param {boolean} [options.cleanUrls=true] The `cleanUrls` option will | ||
* check the cache for the URL with a `.html` added to the end of the end. | ||
* @param {workbox.precaching~urlManipulation} [options.urlManipulation] | ||
* This is a function that should take a URL and return an array of | ||
* alternative URL's that should be checked for precache matches. | ||
* | ||
@@ -1011,2 +1057,13 @@ * @alias workbox.precaching.addRoute | ||
/** | ||
* Add plugins to precaching. | ||
* | ||
* @param {Array<Object>} newPlugins | ||
* | ||
* @alias workbox.precaching.addPlugins | ||
*/ | ||
moduleExports.addPlugins = newPlugins => { | ||
plugins = plugins.concat(newPlugins); | ||
}; | ||
/* | ||
@@ -1033,2 +1090,3 @@ Copyright 2017 Google Inc. | ||
}(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private)); | ||
//# sourceMappingURL=workbox-precaching.dev.js.map |
@@ -1,2 +0,3 @@ | ||
this.workbox=this.workbox||{},this.workbox.precaching=function(e,t,n,r,s){"use strict";try{self.workbox.v["workbox:precaching:3.0.0-alpha.3"]=1}catch(e){}class i{constructor(e,t,n,r){this.e=e,this.t=t,this.n=n;const s=new Request(t);this.r=s,this.s=r?this.i(s):s}i(e){let t=e.url;const n={};if("cache"in Request.prototype)n.cache="reload";else{const e=new URL(t,location),n=encodeURIComponent;e.search+=(e.search?"&":"")+n("_workbox-cache-bust")+"="+n(this.n),t=e.toString()}return new Request(t,n)}}const c="precached-details-models";class o{constructor(t){this.c=e.cacheNames.getPrecacheName(t),this.o=new s.DBWrapper("workbox-precaching",2,{onupgradeneeded:e=>{if(e.oldVersion<2)try{e.target.result.deleteObjectStore("workbox-precaching")}catch(e){}e.target.result.createObjectStore(c)}})}l(e){var t=this;return babelHelpers.asyncToGenerator(function*(){return(yield t.u(e.t))===e.n&&!!(yield(yield caches.open(t.c)).match(e.r))})()}a(){var e=this;return babelHelpers.asyncToGenerator(function*(){return yield e.o.getAllMatching(c,{includeKeys:!0})})()}u(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=yield t.o.get(c,e);return n?n.revision:null})()}h(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.o.put(c,{revision:e.n,url:e.r.url},e.t)})()}d(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.o.delete(c,e)})()}}const l=(()=>{var e=babelHelpers.asyncToGenerator(function*(e){const t=e.clone(),n=yield"body"in t?Promise.resolve(t.body):t.blob();return new Response(n,["headers","status","statusText"].map(function(e){return t[e]}))});return function(t){return e.apply(this,arguments)}})();class u{constructor(t){this.c=e.cacheNames.getPrecacheName(t),this.f=new Map,this.y=new o(this.c)}addToCacheList(e){e.map(e=>{this.b(this.p(e))})}p(e){switch(typeof e){case"string":return new i(e,e,e);case"object":return new i(e,e.url,e.revision||e.url,!!e.revision);default:throw new t.WorkboxError("add-to-cache-list-unexpected-type",{entry:e})}}b(e){const n=this.f.get(e.t);if(n){if(n.n!==e.n)throw new t.WorkboxError("add-to-cache-list-conflicting-entries",{firstEntry:n.e,secondEntry:e.e})}else this.f.set(e.t,e)}install(e={}){var t=this;return babelHelpers.asyncToGenerator(function*(){const e=[],n=[];for(const r of t.f.values())(yield t.y.l(r))?n.push(r):e.push(r);return yield Promise.all(e.map(function(e){return t.w(e)})),{updatedEntries:e,notUpdatedEntries:n}})()}w(e){var t=this;return babelHelpers.asyncToGenerator(function*(){let s=yield n.fetchWrapper.fetch(e.s);return s.redirected&&(s=yield l(s)),yield r.cacheWrapper.put(t.c,e.r,s),yield t.y.h(e),!0})()}cleanup(){var e=this;return babelHelpers.asyncToGenerator(function*(){const t=[];e.f.forEach(function(e){const n=new URL(e.r.url,location).toString();t.push(n)});const[n,r]=yield Promise.all([e.R(t),e._(t)]);return{deletedCacheRequests:n,deletedRevisionDetails:r}})()}R(e){var t=this;return babelHelpers.asyncToGenerator(function*(){if(!(yield caches.has(t.c)))return[];const n=yield caches.open(t.c),r=(yield n.keys()).filter(function(t){return!e.includes(new URL(t.url,location).toString())});return yield Promise.all(r.map(function(e){return n.delete(e)})),r.map(function(e){return e.url})})()}_(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=(yield t.y.a()).filter(function(t){const n=new URL(t.value.url,location).toString();return!e.includes(n)});return yield Promise.all(n.map(function(e){return t.y.d(e.primaryKey)})),n.map(function(e){return e.value.url})})()}getCachedUrls(){return Array.from(this.f.keys()).map(e=>new URL(e,location).href)}}var a=Object.freeze({PrecacheController:u});let h=!1,d=!1,f=!1;const y=e.cacheNames.getPrecacheName(),b=new u(y),p={};return p.precache=(e=>{b.addToCacheList(e),h||e.length<=0||(h=!0,self.addEventListener("install",e=>{e.waitUntil(b.install({suppressWarnings:f}))}),self.addEventListener("activate",e=>{e.waitUntil(b.cleanup())}))}),p.addRoute=(e=>{d||(d=!0,self.addEventListener("fetch",t=>{const n=((e,{ignoreUrlParametersMatching:t=[/^utm_/],directoryIndex:n="index.html"}={})=>{const r=new URL(e,location);r.hash="";const s=b.getCachedUrls();if(-1!==s.indexOf(r.href))return r.href;let i=((e,t)=>{const n=e.search.slice(1).split("&").map(e=>e.split("=")).filter(e=>t.every(t=>!t.test(e[0]))).map(e=>e.join("=")),r=new URL(e);return r.search=n.join("&"),r})(r,t);return-1!==s.indexOf(i.href)?i.href:n&&i.pathname.endsWith("/")&&(i.pathname+=n,-1!==s.indexOf(i.href))?i.href:null})(t.request.url,e);if(!n)return;let r=caches.open(y).then(e=>e.match(n));t.respondWith(r)}))}),p.precacheAndRoute=((e,t)=>{p.precache(e),p.addRoute(t)}),p.suppressWarnings=(e=>{f=e}),Object.assign(p,a)}(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
this.workbox=this.workbox||{},this.workbox.precaching=function(e,t,n,r,s){"use strict";try{self.workbox.v["workbox:precaching:3.0.0-alpha.4"]=1}catch(e){}class i{constructor(e,t,n,r){this.e=e,this.t=t,this.n=n;const s=new Request(t);this.r=s,this.s=r?this.i(s):s}i(e){let t=e.url;const n={};if("cache"in Request.prototype)n.cache="reload";else{const e=new URL(t,location),n=encodeURIComponent;e.search+=(e.search?"&":"")+n("_workbox-cache-bust")+"="+n(this.n),t=e.toString()}return new Request(t,n)}}const c="revision",o="url",l="precached-details-models";class u{constructor(t){this.c=e.cacheNames.getPrecacheName(t),this.o=new s.DBWrapper("workbox-precaching",2,{onupgradeneeded:this.l})}l(e){const t=e.target.result;e.oldVersion<2&&(t.objectStoreNames.contains("workbox-precaching")&&t.deleteObjectStore("workbox-precaching"),t.objectStoreNames.contains(l)&&t.deleteObjectStore(l)),t.createObjectStore(l)}u(e){var t=this;return babelHelpers.asyncToGenerator(function*(){if((yield t.a(e.t))!==e.n)return!1;return!!(yield(yield caches.open(t.c)).match(e.r))})()}h(){var e=this;return babelHelpers.asyncToGenerator(function*(){return yield e.o.getAllMatching(l,{includeKeys:!0})})()}a(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=yield t.o.get(l,e);return n?n[c]:null})()}d(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.o.put(l,{[c]:e.n,[o]:e.r.url},e.t)})()}f(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.o.delete(l,e)})()}}const a=(()=>{var e=babelHelpers.asyncToGenerator(function*(e){const t=e.clone(),n=yield"body"in t?Promise.resolve(t.body):t.blob();return new Response(n,["headers","status","statusText"].map(function(e){return t[e]}))});return function(t){return e.apply(this,arguments)}})();class h{constructor(t){this.c=e.cacheNames.getPrecacheName(t),this.y=new Map,this.b=new u(this.c)}addToCacheList(e){e.map(e=>{this.p(this.w(e))})}w(e){switch(typeof e){case"string":return new i(e,e,e);case"object":return new i(e,e.url,e.revision||e.url,!!e.revision);default:throw new t.WorkboxError("add-to-cache-list-unexpected-type",{entry:e})}}p(e){const n=this.y.get(e.t);if(n){if(n.n!==e.n)throw new t.WorkboxError("add-to-cache-list-conflicting-entries",{firstEntry:n.e,secondEntry:e.e})}else this.y.set(e.t,e)}install(e={}){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=[],r=[];for(const e of t.y.values())(yield t.b.u(e))?r.push(e):n.push(e);return yield Promise.all(n.map(function(n){return t.R(n,e.plugins)})),{updatedEntries:n,notUpdatedEntries:r}})()}R(e,t){var s=this;return babelHelpers.asyncToGenerator(function*(){let i=yield n.fetchWrapper.fetch(e.s,null,t);return i.redirected&&(i=yield a(i)),yield r.cacheWrapper.put(s.c,e.r,i,t),yield s.b.d(e),!0})()}cleanup(){var e=this;return babelHelpers.asyncToGenerator(function*(){const t=[];e.y.forEach(function(e){const n=new URL(e.r.url,location).toString();t.push(n)});const[n,r]=yield Promise.all([e.U(t),e.g(t)]);return{deletedCacheRequests:n,deletedRevisionDetails:r}})()}U(e){var t=this;return babelHelpers.asyncToGenerator(function*(){if(!(yield caches.has(t.c)))return[];const n=yield caches.open(t.c),r=(yield n.keys()).filter(function(t){return!e.includes(new URL(t.url,location).toString())});return yield Promise.all(r.map(function(e){return n.delete(e)})),r.map(function(e){return e.url})})()}g(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=(yield t.b.h()).filter(function(t){const n=new URL(t.value.url,location).toString();return!e.includes(n)});return yield Promise.all(n.map(function(e){return t.b.f(e.primaryKey)})),n.map(function(e){return e.value.url})})()}getCachedUrls(){return Array.from(this.y.keys()).map(e=>new URL(e,location).href)}}var d=Object.freeze({PrecacheController:h});let f=!1,y=!1,b=!1,p=[];const w=e.cacheNames.getPrecacheName(),R=new h(w),v=(e,{ignoreUrlParametersMatching:t=[/^utm_/],directoryIndex:n="index.html",cleanUrls:r=!0,urlManipulation:s=null}={})=>{const i=new URL(e,location);i.hash="";const c=((e,t)=>{const n=e.search.slice(1).split("&").map(e=>e.split("=")).filter(e=>t.every(t=>!t.test(e[0]))).map(e=>e.join("=")),r=new URL(e);return r.search=n.join("&"),r})(i,t);let o=[i,c];if(n&&c.pathname.endsWith("/")){const e=new URL(c);e.pathname+=n,o.push(e)}if(r){const e=new URL(c);e.pathname+=".html",o.push(e)}if(s){const e=s({url:i});o=o.concat(e)}const l=R.getCachedUrls();for(const e of o)if(-1!==l.indexOf(e.href))return e.href;return null},U={};U.precache=(e=>{R.addToCacheList(e),f||e.length<=0||(f=!0,self.addEventListener("install",e=>{e.waitUntil(R.install({suppressWarnings:b,plugins:p}))}),self.addEventListener("activate",e=>{e.waitUntil(R.cleanup())}))}),U.addRoute=(e=>{y||(y=!0,self.addEventListener("fetch",t=>{const n=v(t.request.url,e);if(!n)return;let r=caches.open(w).then(e=>e.match(n));t.respondWith(r)}))}),U.precacheAndRoute=((e,t)=>{U.precache(e),U.addRoute(t)}),U.suppressWarnings=(e=>{b=e}),U.addPlugins=(e=>{p=p.concat(e)});return Object.assign(U,d)}(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
//# sourceMappingURL=workbox-precaching.prod.js.map |
{ | ||
"name": "workbox-precaching", | ||
"version": "3.0.0-alpha.3", | ||
"version": "3.0.0-alpha.4", | ||
"license": "Apache-2.0", | ||
@@ -28,4 +28,4 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "^3.0.0-alpha.3" | ||
"workbox-core": "^3.0.0-alpha.4" | ||
} | ||
} |
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
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
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 1 instance in 1 package
19
1
1994
11
128408
Updatedworkbox-core@^3.0.0-alpha.4