jekyll-pwa-workbox 5.1.4 → 5.1.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pwa-workbox.rb +1 -1
  3. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.dev.js +818 -818
  4. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.prod.js +2 -2
  5. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.dev.js +288 -288
  6. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.prod.js +2 -2
  7. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.dev.js +191 -191
  8. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.prod.js +2 -2
  9. data/lib/vendor/workbox-v5.1.4/workbox-core.dev.js +1858 -1858
  10. data/lib/vendor/workbox-v5.1.4/workbox-core.prod.js +2 -2
  11. data/lib/vendor/workbox-v5.1.4/workbox-expiration.dev.js +649 -649
  12. data/lib/vendor/workbox-v5.1.4/workbox-expiration.prod.js +2 -2
  13. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.dev.js +102 -102
  14. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.prod.js +2 -2
  15. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.dev.js +235 -235
  16. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.prod.js +2 -2
  17. data/lib/vendor/workbox-v5.1.4/workbox-precaching.dev.js +1210 -1210
  18. data/lib/vendor/workbox-v5.1.4/workbox-precaching.prod.js +2 -2
  19. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.dev.js +262 -262
  20. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.prod.js +2 -2
  21. data/lib/vendor/workbox-v5.1.4/workbox-routing.dev.js +923 -923
  22. data/lib/vendor/workbox-v5.1.4/workbox-routing.prod.js +2 -2
  23. data/lib/vendor/workbox-v5.1.4/workbox-strategies.dev.js +923 -923
  24. data/lib/vendor/workbox-v5.1.4/workbox-strategies.prod.js +2 -2
  25. data/lib/vendor/workbox-v5.1.4/workbox-streams.dev.js +318 -318
  26. data/lib/vendor/workbox-v5.1.4/workbox-streams.prod.js +2 -2
  27. data/lib/vendor/workbox-v5.1.4/workbox-sw.js +2 -2
  28. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.es5.mjs +1125 -1125
  29. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.mjs +943 -943
  30. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.umd.js +1136 -1136
  31. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.es5.mjs +2 -2
  32. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.mjs +2 -2
  33. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.umd.js +2 -2
  34. metadata +2 -2
@@ -1,2 +1,2 @@
1
- this.workbox=this.workbox||{},this.workbox.backgroundSync=function(t,e,s,i,n){"use strict";try{self["workbox:background-sync:5.1.4"]&&_()}catch(t){}class a{constructor(t){this.t=t,this.s=new n.DBWrapper("workbox-background-sync",3,{onupgradeneeded:this.i})}async pushEntry(t){delete t.id,t.queueName=this.t,await this.s.add("requests",t)}async unshiftEntry(t){const[e]=await this.s.getAllMatching("requests",{count:1});e?t.id=e.id-1:delete t.id,t.queueName=this.t,await this.s.add("requests",t)}async popEntry(){return this.h({direction:"prev"})}async shiftEntry(){return this.h({direction:"next"})}async getAll(){return await this.s.getAllMatching("requests",{index:"queueName",query:IDBKeyRange.only(this.t)})}async deleteEntry(t){await this.s.delete("requests",t)}async h({direction:t}){const[e]=await this.s.getAllMatching("requests",{direction:t,index:"queueName",query:IDBKeyRange.only(this.t),count:1});if(e)return await this.deleteEntry(e.id),e}i(t){const e=t.target.result;t.oldVersion>0&&t.oldVersion<3&&e.objectStoreNames.contains("requests")&&e.deleteObjectStore("requests");e.createObjectStore("requests",{autoIncrement:!0,keyPath:"id"}).createIndex("queueName","queueName",{unique:!1})}}const r=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class c{constructor(t){"navigate"===t.mode&&(t.mode="same-origin"),this.u=t}static async fromRequest(t){const e={url:t.url,headers:{}};"GET"!==t.method&&(e.body=await t.clone().arrayBuffer());for(const[s,i]of t.headers.entries())e.headers[s]=i;for(const s of r)void 0!==t[s]&&(e[s]=t[s]);return new c(e)}toObject(){const t=Object.assign({},this.u);return t.headers=Object.assign({},this.u.headers),t.body&&(t.body=t.body.slice(0)),t}toRequest(){return new Request(this.u.url,this.u)}clone(){return new c(this.toObject())}}const h=new Set,u=t=>{const e={request:new c(t.requestData).toRequest(),timestamp:t.timestamp};return t.metadata&&(e.metadata=t.metadata),e};class o{constructor(t,{onSync:s,maxRetentionTime:i}={}){if(this.o=!1,this.q=!1,h.has(t))throw new e.WorkboxError("duplicate-queue-name",{name:t});h.add(t),this.l=t,this.m=s||this.replayRequests,this.p=i||10080,this.g=new a(this.l),this.R()}get name(){return this.l}async pushRequest(t){await this.k(t,"push")}async unshiftRequest(t){await this.k(t,"unshift")}async popRequest(){return this.D("pop")}async shiftRequest(){return this.D("shift")}async getAll(){const t=await this.g.getAll(),e=Date.now(),s=[];for(const i of t){const t=60*this.p*1e3;e-i.timestamp>t?await this.g.deleteEntry(i.id):s.push(u(i))}return s}async k({request:t,metadata:e,timestamp:s=Date.now()},i){const n={requestData:(await c.fromRequest(t.clone())).toObject(),timestamp:s};e&&(n.metadata=e),await this.g[i+"Entry"](n),this.o?this.q=!0:await this.registerSync()}async D(t){const e=Date.now(),s=await this.g[t+"Entry"]();if(s){const i=60*this.p*1e3;return e-s.timestamp>i?this.D(t):u(s)}}async replayRequests(){let t;for(;t=await this.shiftRequest();)try{await fetch(t.request.clone())}catch(s){throw await this.unshiftRequest(t),new e.WorkboxError("queue-replay-failed",{name:this.l})}}async registerSync(){if("sync"in self.registration)try{await self.registration.sync.register("workbox-background-sync:"+this.l)}catch(t){}}R(){"sync"in self.registration?self.addEventListener("sync",t=>{if(t.tag==="workbox-background-sync:"+this.l){const e=async()=>{let e;this.o=!0;try{await this.m({queue:this})}catch(t){throw e=t,e}finally{!this.q||e&&!t.lastChance||await this.registerSync(),this.o=!1,this.q=!1}};t.waitUntil(e())}}):this.m({queue:this})}static get _(){return h}}return t.BackgroundSyncPlugin=class{constructor(t,e){this.fetchDidFail=async({request:t})=>{await this.v.pushRequest({request:t})},this.v=new o(t,e)}},t.Queue=o,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private);
2
- //# sourceMappingURL=workbox-background-sync.prod.js.map
1
+ this.workbox=this.workbox||{},this.workbox.backgroundSync=function(t,e,s,i,n){"use strict";try{self["workbox:background-sync:5.1.4"]&&_()}catch(t){}class a{constructor(t){this.t=t,this.s=new n.DBWrapper("workbox-background-sync",3,{onupgradeneeded:this.i})}async pushEntry(t){delete t.id,t.queueName=this.t,await this.s.add("requests",t)}async unshiftEntry(t){const[e]=await this.s.getAllMatching("requests",{count:1});e?t.id=e.id-1:delete t.id,t.queueName=this.t,await this.s.add("requests",t)}async popEntry(){return this.h({direction:"prev"})}async shiftEntry(){return this.h({direction:"next"})}async getAll(){return await this.s.getAllMatching("requests",{index:"queueName",query:IDBKeyRange.only(this.t)})}async deleteEntry(t){await this.s.delete("requests",t)}async h({direction:t}){const[e]=await this.s.getAllMatching("requests",{direction:t,index:"queueName",query:IDBKeyRange.only(this.t),count:1});if(e)return await this.deleteEntry(e.id),e}i(t){const e=t.target.result;t.oldVersion>0&&t.oldVersion<3&&e.objectStoreNames.contains("requests")&&e.deleteObjectStore("requests");e.createObjectStore("requests",{autoIncrement:!0,keyPath:"id"}).createIndex("queueName","queueName",{unique:!1})}}const r=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class c{constructor(t){"navigate"===t.mode&&(t.mode="same-origin"),this.u=t}static async fromRequest(t){const e={url:t.url,headers:{}};"GET"!==t.method&&(e.body=await t.clone().arrayBuffer());for(const[s,i]of t.headers.entries())e.headers[s]=i;for(const s of r)void 0!==t[s]&&(e[s]=t[s]);return new c(e)}toObject(){const t=Object.assign({},this.u);return t.headers=Object.assign({},this.u.headers),t.body&&(t.body=t.body.slice(0)),t}toRequest(){return new Request(this.u.url,this.u)}clone(){return new c(this.toObject())}}const h=new Set,u=t=>{const e={request:new c(t.requestData).toRequest(),timestamp:t.timestamp};return t.metadata&&(e.metadata=t.metadata),e};class o{constructor(t,{onSync:s,maxRetentionTime:i}={}){if(this.o=!1,this.q=!1,h.has(t))throw new e.WorkboxError("duplicate-queue-name",{name:t});h.add(t),this.l=t,this.m=s||this.replayRequests,this.p=i||10080,this.g=new a(this.l),this.R()}get name(){return this.l}async pushRequest(t){await this.k(t,"push")}async unshiftRequest(t){await this.k(t,"unshift")}async popRequest(){return this.D("pop")}async shiftRequest(){return this.D("shift")}async getAll(){const t=await this.g.getAll(),e=Date.now(),s=[];for(const i of t){const t=60*this.p*1e3;e-i.timestamp>t?await this.g.deleteEntry(i.id):s.push(u(i))}return s}async k({request:t,metadata:e,timestamp:s=Date.now()},i){const n={requestData:(await c.fromRequest(t.clone())).toObject(),timestamp:s};e&&(n.metadata=e),await this.g[i+"Entry"](n),this.o?this.q=!0:await this.registerSync()}async D(t){const e=Date.now(),s=await this.g[t+"Entry"]();if(s){const i=60*this.p*1e3;return e-s.timestamp>i?this.D(t):u(s)}}async replayRequests(){let t;for(;t=await this.shiftRequest();)try{await fetch(t.request.clone())}catch(s){throw await this.unshiftRequest(t),new e.WorkboxError("queue-replay-failed",{name:this.l})}}async registerSync(){if("sync"in self.registration)try{await self.registration.sync.register("workbox-background-sync:"+this.l)}catch(t){}}R(){"sync"in self.registration?self.addEventListener("sync",t=>{if(t.tag==="workbox-background-sync:"+this.l){const e=async()=>{let e;this.o=!0;try{await this.m({queue:this})}catch(t){throw e=t,e}finally{!this.q||e&&!t.lastChance||await this.registerSync(),this.o=!1,this.q=!1}};t.waitUntil(e())}}):this.m({queue:this})}static get _(){return h}}return t.BackgroundSyncPlugin=class{constructor(t,e){this.fetchDidFail=async({request:t})=>{await this.v.pushRequest({request:t})},this.v=new o(t,e)}},t.Queue=o,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private);
2
+ //# sourceMappingURL=workbox-background-sync.prod.js.map
@@ -1,288 +1,288 @@
1
- this.workbox = this.workbox || {};
2
- this.workbox.broadcastUpdate = (function (exports, assert_js, timeout_js, resultingClientExists_js, logger_js, WorkboxError_js, dontWaitFor_js) {
3
- 'use strict';
4
-
5
- try {
6
- self['workbox:broadcast-update:5.1.4'] && _();
7
- } catch (e) {}
8
-
9
- /*
10
- Copyright 2018 Google LLC
11
-
12
- Use of this source code is governed by an MIT-style
13
- license that can be found in the LICENSE file or at
14
- https://opensource.org/licenses/MIT.
15
- */
16
- /**
17
- * Given two `Response's`, compares several header values to see if they are
18
- * the same or not.
19
- *
20
- * @param {Response} firstResponse
21
- * @param {Response} secondResponse
22
- * @param {Array<string>} headersToCheck
23
- * @return {boolean}
24
- *
25
- * @memberof module:workbox-broadcast-update
26
- */
27
-
28
- const responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {
29
- {
30
- if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {
31
- throw new WorkboxError_js.WorkboxError('invalid-responses-are-same-args');
32
- }
33
- }
34
-
35
- const atLeastOneHeaderAvailable = headersToCheck.some(header => {
36
- return firstResponse.headers.has(header) && secondResponse.headers.has(header);
37
- });
38
-
39
- if (!atLeastOneHeaderAvailable) {
40
- {
41
- logger_js.logger.warn(`Unable to determine where the response has been updated ` + `because none of the headers that would be checked are present.`);
42
- logger_js.logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);
43
- } // Just return true, indicating the that responses are the same, since we
44
- // can't determine otherwise.
45
-
46
-
47
- return true;
48
- }
49
-
50
- return headersToCheck.every(header => {
51
- const headerStateComparison = firstResponse.headers.has(header) === secondResponse.headers.has(header);
52
- const headerValueComparison = firstResponse.headers.get(header) === secondResponse.headers.get(header);
53
- return headerStateComparison && headerValueComparison;
54
- });
55
- };
56
-
57
- /*
58
- Copyright 2018 Google LLC
59
-
60
- Use of this source code is governed by an MIT-style
61
- license that can be found in the LICENSE file or at
62
- https://opensource.org/licenses/MIT.
63
- */
64
- const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';
65
- const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';
66
- const DEFAULT_HEADERS_TO_CHECK = ['content-length', 'etag', 'last-modified'];
67
-
68
- /*
69
- Copyright 2018 Google LLC
70
-
71
- Use of this source code is governed by an MIT-style
72
- license that can be found in the LICENSE file or at
73
- https://opensource.org/licenses/MIT.
74
- */
75
- // TODO(philipwalton): remove once this Safari bug fix has been released.
76
- // https://bugs.webkit.org/show_bug.cgi?id=201169
77
-
78
- const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
79
- /**
80
- * Generates the default payload used in update messages. By default the
81
- * payload includes the `cacheName` and `updatedURL` fields.
82
- *
83
- * @return Object
84
- * @private
85
- */
86
-
87
- function defaultPayloadGenerator(data) {
88
- return {
89
- cacheName: data.cacheName,
90
- updatedURL: data.request.url
91
- };
92
- }
93
- /**
94
- * Uses the `postMessage()` API to inform any open windows/tabs when a cached
95
- * response has been updated.
96
- *
97
- * For efficiency's sake, the underlying response bodies are not compared;
98
- * only specific response headers are checked.
99
- *
100
- * @memberof module:workbox-broadcast-update
101
- */
102
-
103
-
104
- class BroadcastCacheUpdate {
105
- /**
106
- * Construct a BroadcastCacheUpdate instance with a specific `channelName` to
107
- * broadcast messages on
108
- *
109
- * @param {Object} options
110
- * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]
111
- * A list of headers that will be used to determine whether the responses
112
- * differ.
113
- * @param {string} [options.generatePayload] A function whose return value
114
- * will be used as the `payload` field in any cache update messages sent
115
- * to the window clients.
116
- */
117
- constructor({
118
- headersToCheck,
119
- generatePayload
120
- } = {}) {
121
- this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;
122
- this._generatePayload = generatePayload || defaultPayloadGenerator;
123
- }
124
- /**
125
- * Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
126
- * and sends a message (via `postMessage()`) to all window clients if the
127
- * responses differ (note: neither of the Responses can be
128
- * {@link http://stackoverflow.com/questions/39109789|opaque}).
129
- *
130
- * The message that's posted has the following format (where `payload` can
131
- * be customized via the `generatePayload` option the instance is created
132
- * with):
133
- *
134
- * ```
135
- * {
136
- * type: 'CACHE_UPDATED',
137
- * meta: 'workbox-broadcast-update',
138
- * payload: {
139
- * cacheName: 'the-cache-name',
140
- * updatedURL: 'https://example.com/'
141
- * }
142
- * }
143
- * ```
144
- *
145
- * @param {Object} options
146
- * @param {Response} [options.oldResponse] Cached response to compare.
147
- * @param {Response} options.newResponse Possibly updated response to compare.
148
- * @param {Request} options.request The request.
149
- * @param {string} options.cacheName Name of the cache the responses belong
150
- * to. This is included in the broadcast message.
151
- * @param {Event} [options.event] event An optional event that triggered
152
- * this possible cache update.
153
- * @return {Promise} Resolves once the update is sent.
154
- */
155
-
156
-
157
- async notifyIfUpdated(options) {
158
- {
159
- assert_js.assert.isType(options.cacheName, 'string', {
160
- moduleName: 'workbox-broadcast-update',
161
- className: 'BroadcastCacheUpdate',
162
- funcName: 'notifyIfUpdated',
163
- paramName: 'cacheName'
164
- });
165
- assert_js.assert.isInstance(options.newResponse, Response, {
166
- moduleName: 'workbox-broadcast-update',
167
- className: 'BroadcastCacheUpdate',
168
- funcName: 'notifyIfUpdated',
169
- paramName: 'newResponse'
170
- });
171
- assert_js.assert.isInstance(options.request, Request, {
172
- moduleName: 'workbox-broadcast-update',
173
- className: 'BroadcastCacheUpdate',
174
- funcName: 'notifyIfUpdated',
175
- paramName: 'request'
176
- });
177
- } // Without two responses there is nothing to compare.
178
-
179
-
180
- if (!options.oldResponse) {
181
- return;
182
- }
183
-
184
- if (!responsesAreSame(options.oldResponse, options.newResponse, this._headersToCheck)) {
185
- {
186
- logger_js.logger.log(`Newer response found (and cached) for:`, options.request.url);
187
- }
188
-
189
- const messageData = {
190
- type: CACHE_UPDATED_MESSAGE_TYPE,
191
- meta: CACHE_UPDATED_MESSAGE_META,
192
- payload: this._generatePayload(options)
193
- }; // For navigation requests, wait until the new window client exists
194
- // before sending the message
195
-
196
- if (options.request.mode === 'navigate') {
197
- let resultingClientId;
198
-
199
- if (options.event instanceof FetchEvent) {
200
- resultingClientId = options.event.resultingClientId;
201
- }
202
-
203
- const resultingWin = await resultingClientExists_js.resultingClientExists(resultingClientId); // Safari does not currently implement postMessage buffering and
204
- // there's no good way to feature detect that, so to increase the
205
- // chances of the message being delivered in Safari, we add a timeout.
206
- // We also do this if `resultingClientExists()` didn't return a client,
207
- // which means it timed out, so it's worth waiting a bit longer.
208
-
209
- if (!resultingWin || isSafari) {
210
- // 3500 is chosen because (according to CrUX data) 80% of mobile
211
- // websites hit the DOMContentLoaded event in less than 3.5 seconds.
212
- // And presumably sites implementing service worker are on the
213
- // higher end of the performance spectrum.
214
- await timeout_js.timeout(3500);
215
- }
216
- }
217
-
218
- const windows = await self.clients.matchAll({
219
- type: 'window'
220
- });
221
-
222
- for (const win of windows) {
223
- win.postMessage(messageData);
224
- }
225
- }
226
- }
227
-
228
- }
229
-
230
- /*
231
- Copyright 2018 Google LLC
232
-
233
- Use of this source code is governed by an MIT-style
234
- license that can be found in the LICENSE file or at
235
- https://opensource.org/licenses/MIT.
236
- */
237
- /**
238
- * This plugin will automatically broadcast a message whenever a cached response
239
- * is updated.
240
- *
241
- * @memberof module:workbox-broadcast-update
242
- */
243
-
244
- class BroadcastUpdatePlugin {
245
- /**
246
- * Construct a BroadcastCacheUpdate instance with the passed options and
247
- * calls its [`notifyIfUpdated()`]{@link module:workbox-broadcast-update.BroadcastCacheUpdate~notifyIfUpdated}
248
- * method whenever the plugin's `cacheDidUpdate` callback is invoked.
249
- *
250
- * @param {Object} options
251
- * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]
252
- * A list of headers that will be used to determine whether the responses
253
- * differ.
254
- * @param {string} [options.generatePayload] A function whose return value
255
- * will be used as the `payload` field in any cache update messages sent
256
- * to the window clients.
257
- */
258
- constructor(options) {
259
- /**
260
- * A "lifecycle" callback that will be triggered automatically by the
261
- * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is
262
- * added to a cache.
263
- *
264
- * @private
265
- * @param {Object} options The input object to this function.
266
- * @param {string} options.cacheName Name of the cache being updated.
267
- * @param {Response} [options.oldResponse] The previous cached value, if any.
268
- * @param {Response} options.newResponse The new value in the cache.
269
- * @param {Request} options.request The request that triggered the update.
270
- * @param {Request} [options.event] The event that triggered the update.
271
- */
272
- this.cacheDidUpdate = async options => {
273
- dontWaitFor_js.dontWaitFor(this._broadcastUpdate.notifyIfUpdated(options));
274
- };
275
-
276
- this._broadcastUpdate = new BroadcastCacheUpdate(options);
277
- }
278
-
279
- }
280
-
281
- exports.BroadcastCacheUpdate = BroadcastCacheUpdate;
282
- exports.BroadcastUpdatePlugin = BroadcastUpdatePlugin;
283
- exports.responsesAreSame = responsesAreSame;
284
-
285
- return exports;
286
-
287
- }({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
288
- //# sourceMappingURL=workbox-broadcast-update.dev.js.map
1
+ this.workbox = this.workbox || {};
2
+ this.workbox.broadcastUpdate = (function (exports, assert_js, timeout_js, resultingClientExists_js, logger_js, WorkboxError_js, dontWaitFor_js) {
3
+ 'use strict';
4
+
5
+ try {
6
+ self['workbox:broadcast-update:5.1.4'] && _();
7
+ } catch (e) {}
8
+
9
+ /*
10
+ Copyright 2018 Google LLC
11
+
12
+ Use of this source code is governed by an MIT-style
13
+ license that can be found in the LICENSE file or at
14
+ https://opensource.org/licenses/MIT.
15
+ */
16
+ /**
17
+ * Given two `Response's`, compares several header values to see if they are
18
+ * the same or not.
19
+ *
20
+ * @param {Response} firstResponse
21
+ * @param {Response} secondResponse
22
+ * @param {Array<string>} headersToCheck
23
+ * @return {boolean}
24
+ *
25
+ * @memberof module:workbox-broadcast-update
26
+ */
27
+
28
+ const responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {
29
+ {
30
+ if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {
31
+ throw new WorkboxError_js.WorkboxError('invalid-responses-are-same-args');
32
+ }
33
+ }
34
+
35
+ const atLeastOneHeaderAvailable = headersToCheck.some(header => {
36
+ return firstResponse.headers.has(header) && secondResponse.headers.has(header);
37
+ });
38
+
39
+ if (!atLeastOneHeaderAvailable) {
40
+ {
41
+ logger_js.logger.warn(`Unable to determine where the response has been updated ` + `because none of the headers that would be checked are present.`);
42
+ logger_js.logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);
43
+ } // Just return true, indicating the that responses are the same, since we
44
+ // can't determine otherwise.
45
+
46
+
47
+ return true;
48
+ }
49
+
50
+ return headersToCheck.every(header => {
51
+ const headerStateComparison = firstResponse.headers.has(header) === secondResponse.headers.has(header);
52
+ const headerValueComparison = firstResponse.headers.get(header) === secondResponse.headers.get(header);
53
+ return headerStateComparison && headerValueComparison;
54
+ });
55
+ };
56
+
57
+ /*
58
+ Copyright 2018 Google LLC
59
+
60
+ Use of this source code is governed by an MIT-style
61
+ license that can be found in the LICENSE file or at
62
+ https://opensource.org/licenses/MIT.
63
+ */
64
+ const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';
65
+ const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';
66
+ const DEFAULT_HEADERS_TO_CHECK = ['content-length', 'etag', 'last-modified'];
67
+
68
+ /*
69
+ Copyright 2018 Google LLC
70
+
71
+ Use of this source code is governed by an MIT-style
72
+ license that can be found in the LICENSE file or at
73
+ https://opensource.org/licenses/MIT.
74
+ */
75
+ // TODO(philipwalton): remove once this Safari bug fix has been released.
76
+ // https://bugs.webkit.org/show_bug.cgi?id=201169
77
+
78
+ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
79
+ /**
80
+ * Generates the default payload used in update messages. By default the
81
+ * payload includes the `cacheName` and `updatedURL` fields.
82
+ *
83
+ * @return Object
84
+ * @private
85
+ */
86
+
87
+ function defaultPayloadGenerator(data) {
88
+ return {
89
+ cacheName: data.cacheName,
90
+ updatedURL: data.request.url
91
+ };
92
+ }
93
+ /**
94
+ * Uses the `postMessage()` API to inform any open windows/tabs when a cached
95
+ * response has been updated.
96
+ *
97
+ * For efficiency's sake, the underlying response bodies are not compared;
98
+ * only specific response headers are checked.
99
+ *
100
+ * @memberof module:workbox-broadcast-update
101
+ */
102
+
103
+
104
+ class BroadcastCacheUpdate {
105
+ /**
106
+ * Construct a BroadcastCacheUpdate instance with a specific `channelName` to
107
+ * broadcast messages on
108
+ *
109
+ * @param {Object} options
110
+ * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]
111
+ * A list of headers that will be used to determine whether the responses
112
+ * differ.
113
+ * @param {string} [options.generatePayload] A function whose return value
114
+ * will be used as the `payload` field in any cache update messages sent
115
+ * to the window clients.
116
+ */
117
+ constructor({
118
+ headersToCheck,
119
+ generatePayload
120
+ } = {}) {
121
+ this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;
122
+ this._generatePayload = generatePayload || defaultPayloadGenerator;
123
+ }
124
+ /**
125
+ * Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
126
+ * and sends a message (via `postMessage()`) to all window clients if the
127
+ * responses differ (note: neither of the Responses can be
128
+ * {@link http://stackoverflow.com/questions/39109789|opaque}).
129
+ *
130
+ * The message that's posted has the following format (where `payload` can
131
+ * be customized via the `generatePayload` option the instance is created
132
+ * with):
133
+ *
134
+ * ```
135
+ * {
136
+ * type: 'CACHE_UPDATED',
137
+ * meta: 'workbox-broadcast-update',
138
+ * payload: {
139
+ * cacheName: 'the-cache-name',
140
+ * updatedURL: 'https://example.com/'
141
+ * }
142
+ * }
143
+ * ```
144
+ *
145
+ * @param {Object} options
146
+ * @param {Response} [options.oldResponse] Cached response to compare.
147
+ * @param {Response} options.newResponse Possibly updated response to compare.
148
+ * @param {Request} options.request The request.
149
+ * @param {string} options.cacheName Name of the cache the responses belong
150
+ * to. This is included in the broadcast message.
151
+ * @param {Event} [options.event] event An optional event that triggered
152
+ * this possible cache update.
153
+ * @return {Promise} Resolves once the update is sent.
154
+ */
155
+
156
+
157
+ async notifyIfUpdated(options) {
158
+ {
159
+ assert_js.assert.isType(options.cacheName, 'string', {
160
+ moduleName: 'workbox-broadcast-update',
161
+ className: 'BroadcastCacheUpdate',
162
+ funcName: 'notifyIfUpdated',
163
+ paramName: 'cacheName'
164
+ });
165
+ assert_js.assert.isInstance(options.newResponse, Response, {
166
+ moduleName: 'workbox-broadcast-update',
167
+ className: 'BroadcastCacheUpdate',
168
+ funcName: 'notifyIfUpdated',
169
+ paramName: 'newResponse'
170
+ });
171
+ assert_js.assert.isInstance(options.request, Request, {
172
+ moduleName: 'workbox-broadcast-update',
173
+ className: 'BroadcastCacheUpdate',
174
+ funcName: 'notifyIfUpdated',
175
+ paramName: 'request'
176
+ });
177
+ } // Without two responses there is nothing to compare.
178
+
179
+
180
+ if (!options.oldResponse) {
181
+ return;
182
+ }
183
+
184
+ if (!responsesAreSame(options.oldResponse, options.newResponse, this._headersToCheck)) {
185
+ {
186
+ logger_js.logger.log(`Newer response found (and cached) for:`, options.request.url);
187
+ }
188
+
189
+ const messageData = {
190
+ type: CACHE_UPDATED_MESSAGE_TYPE,
191
+ meta: CACHE_UPDATED_MESSAGE_META,
192
+ payload: this._generatePayload(options)
193
+ }; // For navigation requests, wait until the new window client exists
194
+ // before sending the message
195
+
196
+ if (options.request.mode === 'navigate') {
197
+ let resultingClientId;
198
+
199
+ if (options.event instanceof FetchEvent) {
200
+ resultingClientId = options.event.resultingClientId;
201
+ }
202
+
203
+ const resultingWin = await resultingClientExists_js.resultingClientExists(resultingClientId); // Safari does not currently implement postMessage buffering and
204
+ // there's no good way to feature detect that, so to increase the
205
+ // chances of the message being delivered in Safari, we add a timeout.
206
+ // We also do this if `resultingClientExists()` didn't return a client,
207
+ // which means it timed out, so it's worth waiting a bit longer.
208
+
209
+ if (!resultingWin || isSafari) {
210
+ // 3500 is chosen because (according to CrUX data) 80% of mobile
211
+ // websites hit the DOMContentLoaded event in less than 3.5 seconds.
212
+ // And presumably sites implementing service worker are on the
213
+ // higher end of the performance spectrum.
214
+ await timeout_js.timeout(3500);
215
+ }
216
+ }
217
+
218
+ const windows = await self.clients.matchAll({
219
+ type: 'window'
220
+ });
221
+
222
+ for (const win of windows) {
223
+ win.postMessage(messageData);
224
+ }
225
+ }
226
+ }
227
+
228
+ }
229
+
230
+ /*
231
+ Copyright 2018 Google LLC
232
+
233
+ Use of this source code is governed by an MIT-style
234
+ license that can be found in the LICENSE file or at
235
+ https://opensource.org/licenses/MIT.
236
+ */
237
+ /**
238
+ * This plugin will automatically broadcast a message whenever a cached response
239
+ * is updated.
240
+ *
241
+ * @memberof module:workbox-broadcast-update
242
+ */
243
+
244
+ class BroadcastUpdatePlugin {
245
+ /**
246
+ * Construct a BroadcastCacheUpdate instance with the passed options and
247
+ * calls its [`notifyIfUpdated()`]{@link module:workbox-broadcast-update.BroadcastCacheUpdate~notifyIfUpdated}
248
+ * method whenever the plugin's `cacheDidUpdate` callback is invoked.
249
+ *
250
+ * @param {Object} options
251
+ * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]
252
+ * A list of headers that will be used to determine whether the responses
253
+ * differ.
254
+ * @param {string} [options.generatePayload] A function whose return value
255
+ * will be used as the `payload` field in any cache update messages sent
256
+ * to the window clients.
257
+ */
258
+ constructor(options) {
259
+ /**
260
+ * A "lifecycle" callback that will be triggered automatically by the
261
+ * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is
262
+ * added to a cache.
263
+ *
264
+ * @private
265
+ * @param {Object} options The input object to this function.
266
+ * @param {string} options.cacheName Name of the cache being updated.
267
+ * @param {Response} [options.oldResponse] The previous cached value, if any.
268
+ * @param {Response} options.newResponse The new value in the cache.
269
+ * @param {Request} options.request The request that triggered the update.
270
+ * @param {Request} [options.event] The event that triggered the update.
271
+ */
272
+ this.cacheDidUpdate = async options => {
273
+ dontWaitFor_js.dontWaitFor(this._broadcastUpdate.notifyIfUpdated(options));
274
+ };
275
+
276
+ this._broadcastUpdate = new BroadcastCacheUpdate(options);
277
+ }
278
+
279
+ }
280
+
281
+ exports.BroadcastCacheUpdate = BroadcastCacheUpdate;
282
+ exports.BroadcastUpdatePlugin = BroadcastUpdatePlugin;
283
+ exports.responsesAreSame = responsesAreSame;
284
+
285
+ return exports;
286
+
287
+ }({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
288
+ //# sourceMappingURL=workbox-broadcast-update.dev.js.map