Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

workbox-strategies

Package Overview
Dependencies
Maintainers
5
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-strategies - npm Package Compare versions

Comparing version 6.1.0 to 6.1.1

2

_version.js
"use strict";
// @ts-ignore
try {
self['workbox:strategies:6.1.0'] && _();
self['workbox:strategies:6.1.1'] && _();
}
catch (e) { }

@@ -24,3 +24,3 @@ this.workbox = this.workbox || {};

try {
self['workbox:strategies:6.1.0'] && _();
self['workbox:strategies:6.1.1'] && _();
} catch (e) {}

@@ -130,4 +130,4 @@

* Fetches a given request (and invokes any applicable plugin callback
* methods) using the `fetchOptions` and `plugins` defined on the strategy
* object.
* methods) using the `fetchOptions` (for non-navigation requests) and
* `plugins` defined on the `Strategy` object.
*

@@ -617,4 +617,5 @@ * The following plugin lifecycle methods are invoked when using this method:

* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters}
* of all fetch() requests made by this strategy.
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] The

@@ -1069,11 +1070,12 @@ * [`CacheQueryOptions`]{@link https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions}

* @param {Object} [options]
* @param {string} [options.cacheName Cache name to store and retrieve
* @param {string} [options.cacheName] Cache name to store and retrieve
* requests. Defaults to cache names provided by
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} [options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* to use in conjunction with this caching strategy.
* @param {Object} [options.fetchOptions Values passed along to the
* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* @param {Object} [options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* @param {number} [options.networkTimeoutSeconds] If set, any network requests

@@ -1153,18 +1155,12 @@ * that fail to respond within the timeout will fallback to the cache.

promises.push(networkPromise);
const response = await handler.waitUntil((async () => {
// Promise.race() will resolve as soon as the first promise resolves.
return (await handler.waitUntil(Promise.race(promises))) || ( // If Promise.race() resolved with null, it might be due to a network
// timeout + a cache miss. If that were to happen, we'd rather wait until
// the networkPromise resolves instead of returning null.
// Note that it's fine to await an already-resolved promise, so we don't
// have to check to see if it's still "in flight".
await networkPromise);
})());
for (const promise of promises) {
handler.waitUntil(promise);
} // Promise.race() will resolve as soon as the first promise resolves.
let response = await Promise.race(promises); // If Promise.race() resolved with null, it might be due to a network
// timeout + a cache miss. If that were to happen, we'd rather wait until
// the networkPromise resolves instead of returning null.
// Note that it's fine to await an already-resolved promise, so we don't
// have to check to see if it's still "in flight".
if (!response) {
response = await networkPromise;
}
{

@@ -1306,3 +1302,4 @@ logger_js.logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));

* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {number} [options.networkTimeoutSeconds] If set, any network requests

@@ -1410,12 +1407,13 @@ * that fail to respond within the timeout will result in a network error.

/**
* @param {Object} options
* @param {string} options.cacheName Cache name to store and retrieve
* @param {Object} [options]
* @param {string} [options.cacheName] Cache name to store and retrieve
* requests. Defaults to cache names provided by
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* to use in conjunction with this caching strategy.
* @param {Object} options.fetchOptions Values passed along to the
* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
*/

@@ -1422,0 +1420,0 @@ constructor(options) {

@@ -1,2 +0,2 @@

this.workbox=this.workbox||{},this.workbox.strategies=function(t,e,s,r,i,n,a,o,c){"use strict";function h(){return(h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(t[r]=s[r])}return t}).apply(this,arguments)}try{self["workbox:strategies:6.1.0"]&&_()}catch(t){}function l(t){return"string"==typeof t?new Request(t):t}class u{constructor(t,e){this.vt={},Object.assign(this,e),this.event=e.event,this.ht=t,this.bt=new a.Deferred,this._t=[],this.kt=[...t.plugins],this.xt=new Map;for(const t of this.kt)this.xt.set(t,{});this.event.waitUntil(this.bt.promise)}fetch(t){return this.waitUntil((async()=>{const{event:e}=this;let r=l(t);if("navigate"===r.mode&&e instanceof FetchEvent&&e.preloadResponse){const t=await e.preloadResponse;if(t)return t}const i=this.hasCallback("fetchDidFail")?r.clone():null;try{for(const t of this.iterateCallbacks("requestWillFetch"))r=await t({request:r.clone(),event:e})}catch(t){throw new s.WorkboxError("plugin-error-request-will-fetch",{thrownError:t})}const n=r.clone();try{let t;t=await fetch(r,"navigate"===r.mode?void 0:this.ht.fetchOptions);for(const s of this.iterateCallbacks("fetchDidSucceed"))t=await s({event:e,request:n,response:t});return t}catch(t){throw i&&await this.runCallbacks("fetchDidFail",{error:t,event:e,originalRequest:i.clone(),request:n.clone()}),t}})())}async fetchAndCachePut(t){const e=await this.fetch(t),s=e.clone();return this.waitUntil(this.cachePut(t,s)),e}cacheMatch(t){return this.waitUntil((async()=>{const e=l(t);let s;const{cacheName:r,matchOptions:i}=this.ht,n=await this.getCacheKey(e,"read"),a=h({},i,{cacheName:r});s=await caches.match(n,a);for(const t of this.iterateCallbacks("cachedResponseWillBeUsed"))s=await t({cacheName:r,matchOptions:i,cachedResponse:s,request:n,event:this.event})||void 0;return s})())}async cachePut(t,e){const r=l(t);await c.timeout(0);const a=await this.getCacheKey(r,"write");if(!e)throw new s.WorkboxError("cache-put-with-no-response",{url:i.getFriendlyURL(a.url)});const h=await this.Rt(e);if(!h)return!1;const{cacheName:u,matchOptions:w}=this.ht,f=await self.caches.open(u),d=this.hasCallback("cacheDidUpdate"),p=d?await n.cacheMatchIgnoreParams(f,a.clone(),["__WB_REVISION__"],w):null;try{await f.put(a,d?h.clone():h)}catch(t){throw"QuotaExceededError"===t.name&&await o.executeQuotaErrorCallbacks(),t}for(const t of this.iterateCallbacks("cacheDidUpdate"))await t({cacheName:u,oldResponse:p,newResponse:h.clone(),request:a,event:this.event});return!0}async getCacheKey(t,e){if(!this.vt[e]){let s=t;for(const t of this.iterateCallbacks("cacheKeyWillBeUsed"))s=l(await t({mode:e,request:s,event:this.event,params:this.params}));this.vt[e]=s}return this.vt[e]}hasCallback(t){for(const e of this.ht.plugins)if(t in e)return!0;return!1}async runCallbacks(t,e){for(const s of this.iterateCallbacks(t))await s(e)}*iterateCallbacks(t){for(const e of this.ht.plugins)if("function"==typeof e[t]){const s=this.xt.get(e),r=r=>{const i=h({},r,{state:s});return e[t](i)};yield r}}waitUntil(t){return this._t.push(t),t}async doneWaiting(){let t;for(;t=this._t.shift();)await t}destroy(){this.bt.resolve()}async Rt(t){let e=t,s=!1;for(const t of this.iterateCallbacks("cacheWillUpdate"))if(e=await t({request:this.request,response:e,event:this.event})||void 0,s=!0,!e)break;return s||e&&200!==e.status&&(e=void 0),e}}class w{constructor(t={}){this.cacheName=r.cacheNames.getRuntimeName(t.cacheName),this.plugins=t.plugins||[],this.fetchOptions=t.fetchOptions,this.matchOptions=t.matchOptions}handle(t){const[e]=this.handleAll(t);return e}handleAll(t){t instanceof FetchEvent&&(t={event:t,request:t.request});const e=t.event,s="string"==typeof t.request?new Request(t.request):t.request,r="params"in t?t.params:void 0,i=new u(this,{event:e,request:s,params:r}),n=this.Wt(i,s,e);return[n,this.Ut(n,i,s,e)]}async Wt(t,e,r){await t.runCallbacks("handlerWillStart",{event:r,request:e});let i=void 0;try{if(i=await this._handle(e,t),!i||"error"===i.type)throw new s.WorkboxError("no-response",{url:e.url})}catch(s){for(const n of t.iterateCallbacks("handlerDidError"))if(i=await n({error:s,event:r,request:e}),i)break;if(!i)throw s}for(const s of t.iterateCallbacks("handlerWillRespond"))i=await s({event:r,request:e,response:i});return i}async Ut(t,e,s,r){let i,n;try{i=await t}catch(n){}try{await e.runCallbacks("handlerDidRespond",{event:r,request:s,response:i}),await e.doneWaiting()}catch(t){n=t}if(await e.runCallbacks("handlerDidComplete",{event:r,request:s,response:i,error:n}),e.destroy(),n)throw n}}const f={cacheWillUpdate:async({response:t})=>200===t.status||0===t.status?t:null};return t.CacheFirst=class extends w{async _handle(t,e){let r,i=await e.cacheMatch(t);if(!i)try{i=await e.fetchAndCachePut(t)}catch(t){r=t}if(!i)throw new s.WorkboxError("no-response",{url:t.url,error:r});return i}},t.CacheOnly=class extends w{async _handle(t,e){const r=await e.cacheMatch(t);if(!r)throw new s.WorkboxError("no-response",{url:t.url});return r}},t.NetworkFirst=class extends w{constructor(t={}){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f),this.Ct=t.networkTimeoutSeconds||0}async _handle(t,e){const r=[],i=[];let n;if(this.Ct){const{id:s,promise:a}=this.Dt({request:t,logs:r,handler:e});n=s,i.push(a)}const a=this.Et({timeoutId:n,request:t,logs:r,handler:e});i.push(a);for(const t of i)e.waitUntil(t);let o=await Promise.race(i);if(o||(o=await a),!o)throw new s.WorkboxError("no-response",{url:t.url});return o}Dt({request:t,logs:e,handler:s}){let r;return{promise:new Promise((e=>{r=setTimeout((async()=>{e(await s.cacheMatch(t))}),1e3*this.Ct)})),id:r}}async Et({timeoutId:t,request:e,logs:s,handler:r}){let i,n;try{n=await r.fetchAndCachePut(e)}catch(t){i=t}return t&&clearTimeout(t),!i&&n||(n=await r.cacheMatch(e)),n}},t.NetworkOnly=class extends w{constructor(t={}){super(t),this.Ct=t.networkTimeoutSeconds||0}async _handle(t,e){let r,i=void 0;try{const s=[e.fetch(t)];if(this.Ct){const t=c.timeout(1e3*this.Ct);s.push(t)}if(r=await Promise.race(s),!r)throw new Error("Timed out the network response after "+this.Ct+" seconds.")}catch(t){i=t}if(!r)throw new s.WorkboxError("no-response",{url:t.url,error:i});return r}},t.StaleWhileRevalidate=class extends w{constructor(t){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f)}async _handle(t,e){const r=e.fetchAndCachePut(t).catch((()=>{}));let i,n=await e.cacheMatch(t);if(n);else try{n=await r}catch(t){i=t}if(!n)throw new s.WorkboxError("no-response",{url:t.url,error:i});return n}},t.Strategy=w,t.StrategyHandler=u,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private);
this.workbox=this.workbox||{},this.workbox.strategies=function(t,e,s,r,i,a,n,o,c){"use strict";function h(){return(h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(t[r]=s[r])}return t}).apply(this,arguments)}try{self["workbox:strategies:6.1.1"]&&_()}catch(t){}function l(t){return"string"==typeof t?new Request(t):t}class u{constructor(t,e){this.vt={},Object.assign(this,e),this.event=e.event,this.ht=t,this.bt=new n.Deferred,this._t=[],this.kt=[...t.plugins],this.xt=new Map;for(const t of this.kt)this.xt.set(t,{});this.event.waitUntil(this.bt.promise)}fetch(t){return this.waitUntil((async()=>{const{event:e}=this;let r=l(t);if("navigate"===r.mode&&e instanceof FetchEvent&&e.preloadResponse){const t=await e.preloadResponse;if(t)return t}const i=this.hasCallback("fetchDidFail")?r.clone():null;try{for(const t of this.iterateCallbacks("requestWillFetch"))r=await t({request:r.clone(),event:e})}catch(t){throw new s.WorkboxError("plugin-error-request-will-fetch",{thrownError:t})}const a=r.clone();try{let t;t=await fetch(r,"navigate"===r.mode?void 0:this.ht.fetchOptions);for(const s of this.iterateCallbacks("fetchDidSucceed"))t=await s({event:e,request:a,response:t});return t}catch(t){throw i&&await this.runCallbacks("fetchDidFail",{error:t,event:e,originalRequest:i.clone(),request:a.clone()}),t}})())}async fetchAndCachePut(t){const e=await this.fetch(t),s=e.clone();return this.waitUntil(this.cachePut(t,s)),e}cacheMatch(t){return this.waitUntil((async()=>{const e=l(t);let s;const{cacheName:r,matchOptions:i}=this.ht,a=await this.getCacheKey(e,"read"),n=h({},i,{cacheName:r});s=await caches.match(a,n);for(const t of this.iterateCallbacks("cachedResponseWillBeUsed"))s=await t({cacheName:r,matchOptions:i,cachedResponse:s,request:a,event:this.event})||void 0;return s})())}async cachePut(t,e){const r=l(t);await c.timeout(0);const n=await this.getCacheKey(r,"write");if(!e)throw new s.WorkboxError("cache-put-with-no-response",{url:i.getFriendlyURL(n.url)});const h=await this.Rt(e);if(!h)return!1;const{cacheName:u,matchOptions:w}=this.ht,f=await self.caches.open(u),d=this.hasCallback("cacheDidUpdate"),p=d?await a.cacheMatchIgnoreParams(f,n.clone(),["__WB_REVISION__"],w):null;try{await f.put(n,d?h.clone():h)}catch(t){throw"QuotaExceededError"===t.name&&await o.executeQuotaErrorCallbacks(),t}for(const t of this.iterateCallbacks("cacheDidUpdate"))await t({cacheName:u,oldResponse:p,newResponse:h.clone(),request:n,event:this.event});return!0}async getCacheKey(t,e){if(!this.vt[e]){let s=t;for(const t of this.iterateCallbacks("cacheKeyWillBeUsed"))s=l(await t({mode:e,request:s,event:this.event,params:this.params}));this.vt[e]=s}return this.vt[e]}hasCallback(t){for(const e of this.ht.plugins)if(t in e)return!0;return!1}async runCallbacks(t,e){for(const s of this.iterateCallbacks(t))await s(e)}*iterateCallbacks(t){for(const e of this.ht.plugins)if("function"==typeof e[t]){const s=this.xt.get(e),r=r=>{const i=h({},r,{state:s});return e[t](i)};yield r}}waitUntil(t){return this._t.push(t),t}async doneWaiting(){let t;for(;t=this._t.shift();)await t}destroy(){this.bt.resolve()}async Rt(t){let e=t,s=!1;for(const t of this.iterateCallbacks("cacheWillUpdate"))if(e=await t({request:this.request,response:e,event:this.event})||void 0,s=!0,!e)break;return s||e&&200!==e.status&&(e=void 0),e}}class w{constructor(t={}){this.cacheName=r.cacheNames.getRuntimeName(t.cacheName),this.plugins=t.plugins||[],this.fetchOptions=t.fetchOptions,this.matchOptions=t.matchOptions}handle(t){const[e]=this.handleAll(t);return e}handleAll(t){t instanceof FetchEvent&&(t={event:t,request:t.request});const e=t.event,s="string"==typeof t.request?new Request(t.request):t.request,r="params"in t?t.params:void 0,i=new u(this,{event:e,request:s,params:r}),a=this.Wt(i,s,e);return[a,this.Ut(a,i,s,e)]}async Wt(t,e,r){await t.runCallbacks("handlerWillStart",{event:r,request:e});let i=void 0;try{if(i=await this._handle(e,t),!i||"error"===i.type)throw new s.WorkboxError("no-response",{url:e.url})}catch(s){for(const a of t.iterateCallbacks("handlerDidError"))if(i=await a({error:s,event:r,request:e}),i)break;if(!i)throw s}for(const s of t.iterateCallbacks("handlerWillRespond"))i=await s({event:r,request:e,response:i});return i}async Ut(t,e,s,r){let i,a;try{i=await t}catch(a){}try{await e.runCallbacks("handlerDidRespond",{event:r,request:s,response:i}),await e.doneWaiting()}catch(t){a=t}if(await e.runCallbacks("handlerDidComplete",{event:r,request:s,response:i,error:a}),e.destroy(),a)throw a}}const f={cacheWillUpdate:async({response:t})=>200===t.status||0===t.status?t:null};return t.CacheFirst=class extends w{async _handle(t,e){let r,i=await e.cacheMatch(t);if(!i)try{i=await e.fetchAndCachePut(t)}catch(t){r=t}if(!i)throw new s.WorkboxError("no-response",{url:t.url,error:r});return i}},t.CacheOnly=class extends w{async _handle(t,e){const r=await e.cacheMatch(t);if(!r)throw new s.WorkboxError("no-response",{url:t.url});return r}},t.NetworkFirst=class extends w{constructor(t={}){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f),this.Ct=t.networkTimeoutSeconds||0}async _handle(t,e){const r=[],i=[];let a;if(this.Ct){const{id:s,promise:n}=this.Dt({request:t,logs:r,handler:e});a=s,i.push(n)}const n=this.Et({timeoutId:a,request:t,logs:r,handler:e});i.push(n);const o=await e.waitUntil((async()=>await e.waitUntil(Promise.race(i))||await n)());if(!o)throw new s.WorkboxError("no-response",{url:t.url});return o}Dt({request:t,logs:e,handler:s}){let r;return{promise:new Promise((e=>{r=setTimeout((async()=>{e(await s.cacheMatch(t))}),1e3*this.Ct)})),id:r}}async Et({timeoutId:t,request:e,logs:s,handler:r}){let i,a;try{a=await r.fetchAndCachePut(e)}catch(t){i=t}return t&&clearTimeout(t),!i&&a||(a=await r.cacheMatch(e)),a}},t.NetworkOnly=class extends w{constructor(t={}){super(t),this.Ct=t.networkTimeoutSeconds||0}async _handle(t,e){let r,i=void 0;try{const s=[e.fetch(t)];if(this.Ct){const t=c.timeout(1e3*this.Ct);s.push(t)}if(r=await Promise.race(s),!r)throw new Error("Timed out the network response after "+this.Ct+" seconds.")}catch(t){i=t}if(!r)throw new s.WorkboxError("no-response",{url:t.url,error:i});return r}},t.StaleWhileRevalidate=class extends w{constructor(t){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f)}async _handle(t,e){const r=e.fetchAndCachePut(t).catch((()=>{}));let i,a=await e.cacheMatch(t);if(a);else try{a=await r}catch(t){i=t}if(!a)throw new s.WorkboxError("no-response",{url:t.url,error:i});return a}},t.Strategy=w,t.StrategyHandler=u,t}({},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-strategies.prod.js.map

@@ -27,11 +27,12 @@ import { Strategy, StrategyOptions } from './Strategy.js';

* @param {Object} [options]
* @param {string} [options.cacheName Cache name to store and retrieve
* @param {string} [options.cacheName] Cache name to store and retrieve
* requests. Defaults to cache names provided by
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} [options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* to use in conjunction with this caching strategy.
* @param {Object} [options.fetchOptions Values passed along to the
* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* @param {Object} [options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* @param {number} [options.networkTimeoutSeconds] If set, any network requests

@@ -38,0 +39,0 @@ * that fail to respond within the timeout will fallback to the cache.

@@ -34,11 +34,12 @@ /*

* @param {Object} [options]
* @param {string} [options.cacheName Cache name to store and retrieve
* @param {string} [options.cacheName] Cache name to store and retrieve
* requests. Defaults to cache names provided by
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} [options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* to use in conjunction with this caching strategy.
* @param {Object} [options.fetchOptions Values passed along to the
* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* @param {Object} [options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* @param {number} [options.networkTimeoutSeconds] If set, any network requests

@@ -96,15 +97,12 @@ * that fail to respond within the timeout will fallback to the cache.

promises.push(networkPromise);
for (const promise of promises) {
handler.waitUntil(promise);
}
// Promise.race() will resolve as soon as the first promise resolves.
let response = await Promise.race(promises);
// If Promise.race() resolved with null, it might be due to a network
// timeout + a cache miss. If that were to happen, we'd rather wait until
// the networkPromise resolves instead of returning null.
// Note that it's fine to await an already-resolved promise, so we don't
// have to check to see if it's still "in flight".
if (!response) {
response = await networkPromise;
}
const response = await handler.waitUntil((async () => {
// Promise.race() will resolve as soon as the first promise resolves.
return await handler.waitUntil(Promise.race(promises)) ||
// If Promise.race() resolved with null, it might be due to a network
// timeout + a cache miss. If that were to happen, we'd rather wait until
// the networkPromise resolves instead of returning null.
// Note that it's fine to await an already-resolved promise, so we don't
// have to check to see if it's still "in flight".
await networkPromise;
})());
if (process.env.NODE_ENV !== 'production') {

@@ -111,0 +109,0 @@ logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));

@@ -28,3 +28,4 @@ import { Strategy, StrategyOptions } from './Strategy.js';

* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {number} [options.networkTimeoutSeconds] If set, any network requests

@@ -31,0 +32,0 @@ * that fail to respond within the timeout will result in a network error.

@@ -35,3 +35,4 @@ /*

* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {number} [options.networkTimeoutSeconds] If set, any network requests

@@ -38,0 +39,0 @@ * that fail to respond within the timeout will result in a network error.

{
"name": "workbox-strategies",
"version": "6.1.0",
"version": "6.1.1",
"license": "MIT",

@@ -26,5 +26,5 @@ "author": "Google's Web DevRel Team",

"dependencies": {
"workbox-core": "^6.1.0"
"workbox-core": "^6.1.1"
},
"gitHead": "8f1a9f2cd863ae93987a5cdfc1e3e799635c6e44"
"gitHead": "e103c29615990b6bfb28cd0b81f80412aaaa7aab"
}
// @ts-ignore
try{self['workbox:strategies:6.1.0']&&_()}catch(e){}
try{self['workbox:strategies:6.1.1']&&_()}catch(e){}

@@ -45,11 +45,12 @@ /*

* @param {Object} [options]
* @param {string} [options.cacheName Cache name to store and retrieve
* @param {string} [options.cacheName] Cache name to store and retrieve
* requests. Defaults to cache names provided by
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} [options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* to use in conjunction with this caching strategy.
* @param {Object} [options.fetchOptions Values passed along to the
* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* @param {Object} [options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* @param {number} [options.networkTimeoutSeconds] If set, any network requests

@@ -103,3 +104,3 @@ * that fail to respond within the timeout will fallback to the cache.

const promises = [];
const promises: Promise<Response | undefined>[] = [];
let timeoutId: number | undefined;

@@ -117,16 +118,13 @@

promises.push(networkPromise);
for (const promise of promises) {
handler.waitUntil(promise);
}
// Promise.race() will resolve as soon as the first promise resolves.
let response = await Promise.race(promises);
// If Promise.race() resolved with null, it might be due to a network
// timeout + a cache miss. If that were to happen, we'd rather wait until
// the networkPromise resolves instead of returning null.
// Note that it's fine to await an already-resolved promise, so we don't
// have to check to see if it's still "in flight".
if (!response) {
response = await networkPromise;
}
const response = await handler.waitUntil((async () => {
// Promise.race() will resolve as soon as the first promise resolves.
return await handler.waitUntil(Promise.race(promises)) ||
// If Promise.race() resolved with null, it might be due to a network
// timeout + a cache miss. If that were to happen, we'd rather wait until
// the networkPromise resolves instead of returning null.
// Note that it's fine to await an already-resolved promise, so we don't
// have to check to see if it's still "in flight".
await networkPromise;
})());

@@ -133,0 +131,0 @@ if (process.env.NODE_ENV !== 'production') {

@@ -46,3 +46,4 @@ /*

* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {number} [options.networkTimeoutSeconds] If set, any network requests

@@ -49,0 +50,0 @@ * that fail to respond within the timeout will result in a network error.

@@ -43,12 +43,13 @@ /*

/**
* @param {Object} options
* @param {string} options.cacheName Cache name to store and retrieve
* @param {Object} [options]
* @param {string} [options.cacheName] Cache name to store and retrieve
* requests. Defaults to cache names provided by
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* to use in conjunction with this caching strategy.
* @param {Object} options.fetchOptions Values passed along to the
* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
*/

@@ -55,0 +56,0 @@ constructor(options: StrategyOptions) {

@@ -58,4 +58,5 @@ /*

* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters}
* of all fetch() requests made by this strategy.
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] The

@@ -62,0 +63,0 @@ * [`CacheQueryOptions`]{@link https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions}

@@ -139,4 +139,4 @@ /*

* Fetches a given request (and invokes any applicable plugin callback
* methods) using the `fetchOptions` and `plugins` defined on the strategy
* object.
* methods) using the `fetchOptions` (for non-navigation requests) and
* `plugins` defined on the `Strategy` object.
*

@@ -501,3 +501,3 @@ * The following plugin lifecycle methods are invoked when using this method:

*/
waitUntil(promise: Promise<any>): Promise<any> {
waitUntil<T>(promise: Promise<T>): Promise<T> {
this._extendLifetimePromises.push(promise);

@@ -504,0 +504,0 @@ return promise;

@@ -27,12 +27,13 @@ import { Strategy, StrategyOptions } from './Strategy.js';

/**
* @param {Object} options
* @param {string} options.cacheName Cache name to store and retrieve
* @param {Object} [options]
* @param {string} [options.cacheName] Cache name to store and retrieve
* requests. Defaults to cache names provided by
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* to use in conjunction with this caching strategy.
* @param {Object} options.fetchOptions Values passed along to the
* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
*/

@@ -39,0 +40,0 @@ constructor(options: StrategyOptions);

@@ -38,12 +38,13 @@ /*

/**
* @param {Object} options
* @param {string} options.cacheName Cache name to store and retrieve
* @param {Object} [options]
* @param {string} [options.cacheName] Cache name to store and retrieve
* requests. Defaults to cache names provided by
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* @param {Array<Object>} [options.plugins] [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
* to use in conjunction with this caching strategy.
* @param {Object} options.fetchOptions Values passed along to the
* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of all fetch() requests made by this strategy.
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
*/

@@ -50,0 +51,0 @@ constructor(options) {

@@ -36,4 +36,5 @@ import { HandlerCallbackOptions, RouteHandlerObject, WorkboxPlugin } from 'workbox-core/types.js';

* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters}
* of all fetch() requests made by this strategy.
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] The

@@ -40,0 +41,0 @@ * [`CacheQueryOptions`]{@link https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions}

@@ -35,4 +35,5 @@ /*

* @param {Object} [options.fetchOptions] Values passed along to the
* [`init`]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters}
* of all fetch() requests made by this strategy.
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
* of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796)
* `fetch()` requests made by this strategy.
* @param {Object} [options.matchOptions] The

@@ -39,0 +40,0 @@ * [`CacheQueryOptions`]{@link https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions}

@@ -44,4 +44,4 @@ import { HandlerCallbackOptions, WorkboxPlugin, WorkboxPluginCallbackParam } from 'workbox-core/types.js';

* Fetches a given request (and invokes any applicable plugin callback
* methods) using the `fetchOptions` and `plugins` defined on the strategy
* object.
* methods) using the `fetchOptions` (for non-navigation requests) and
* `plugins` defined on the `Strategy` object.
*

@@ -157,3 +157,3 @@ * The following plugin lifecycle methods are invoked when using this method:

*/
waitUntil(promise: Promise<any>): Promise<any>;
waitUntil<T>(promise: Promise<T>): Promise<T>;
/**

@@ -160,0 +160,0 @@ * Returns a promise that resolves once all promises passed to

@@ -110,4 +110,4 @@ /*

* Fetches a given request (and invokes any applicable plugin callback
* methods) using the `fetchOptions` and `plugins` defined on the strategy
* object.
* methods) using the `fetchOptions` (for non-navigation requests) and
* `plugins` defined on the `Strategy` object.
*

@@ -114,0 +114,0 @@ * The following plugin lifecycle methods are invoked when using this method:

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc