jekyll-pwa-plugin 1.0.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pwa-plugin.rb +18 -36
  3. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.dev.js +593 -0
  4. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.dev.js.map +1 -0
  5. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.prod.js +3 -0
  6. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.prod.js.map +1 -0
  7. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.dev.js +395 -0
  8. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.dev.js.map +1 -0
  9. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.prod.js +3 -0
  10. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.prod.js.map +1 -0
  11. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.dev.js +740 -0
  12. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.dev.js.map +1 -0
  13. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.prod.js +3 -0
  14. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.prod.js.map +1 -0
  15. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.dev.js +236 -0
  16. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.dev.js.map +1 -0
  17. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.prod.js +3 -0
  18. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.prod.js.map +1 -0
  19. data/lib/vendor/workbox-v3.3.1/workbox-core.dev.js +1690 -0
  20. data/lib/vendor/workbox-v3.3.1/workbox-core.dev.js.map +1 -0
  21. data/lib/vendor/workbox-v3.3.1/workbox-core.prod.js +3 -0
  22. data/lib/vendor/workbox-v3.3.1/workbox-core.prod.js.map +1 -0
  23. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.dev.js +255 -0
  24. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.dev.js.map +1 -0
  25. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.prod.js +3 -0
  26. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.prod.js.map +1 -0
  27. data/lib/vendor/workbox-v3.3.1/workbox-precaching.dev.js +1149 -0
  28. data/lib/vendor/workbox-v3.3.1/workbox-precaching.dev.js.map +1 -0
  29. data/lib/vendor/workbox-v3.3.1/workbox-precaching.prod.js +3 -0
  30. data/lib/vendor/workbox-v3.3.1/workbox-precaching.prod.js.map +1 -0
  31. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.dev.js +299 -0
  32. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.dev.js.map +1 -0
  33. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.prod.js +3 -0
  34. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.prod.js.map +1 -0
  35. data/lib/vendor/workbox-v3.3.1/workbox-routing.dev.js +863 -0
  36. data/lib/vendor/workbox-v3.3.1/workbox-routing.dev.js.map +1 -0
  37. data/lib/vendor/workbox-v3.3.1/workbox-routing.prod.js +3 -0
  38. data/lib/vendor/workbox-v3.3.1/workbox-routing.prod.js.map +1 -0
  39. data/lib/vendor/workbox-v3.3.1/workbox-strategies.dev.js +1091 -0
  40. data/lib/vendor/workbox-v3.3.1/workbox-strategies.dev.js.map +1 -0
  41. data/lib/vendor/workbox-v3.3.1/workbox-strategies.prod.js +3 -0
  42. data/lib/vendor/workbox-v3.3.1/workbox-strategies.prod.js.map +1 -0
  43. data/lib/vendor/workbox-v3.3.1/workbox-streams.dev.js +390 -0
  44. data/lib/vendor/workbox-v3.3.1/workbox-streams.dev.js.map +1 -0
  45. data/lib/vendor/workbox-v3.3.1/workbox-streams.prod.js +3 -0
  46. data/lib/vendor/workbox-v3.3.1/workbox-streams.prod.js.map +1 -0
  47. data/lib/vendor/workbox-v3.3.1/workbox-sw.js +3 -0
  48. data/lib/vendor/workbox-v3.3.1/workbox-sw.js.map +1 -0
  49. metadata +48 -3
  50. data/lib/vendor/workbox-sw.prod.v2.1.1.js +0 -186
@@ -0,0 +1,1091 @@
1
+ this.workbox = this.workbox || {};
2
+ this.workbox.strategies = (function (logger_mjs,assert_mjs,cacheNames_mjs,cacheWrapper_mjs,fetchWrapper_mjs,getFriendlyURL_mjs) {
3
+ 'use strict';
4
+
5
+ try {
6
+ self.workbox.v['workbox:strategies:3.3.1'] = 1;
7
+ } catch (e) {} // eslint-disable-line
8
+
9
+ /*
10
+ Copyright 2018 Google Inc. All Rights Reserved.
11
+ Licensed under the Apache License, Version 2.0 (the "License");
12
+ you may not use this file except in compliance with the License.
13
+ You may obtain a copy of the License at
14
+
15
+ http://www.apache.org/licenses/LICENSE-2.0
16
+
17
+ Unless required by applicable law or agreed to in writing, software
18
+ distributed under the License is distributed on an "AS IS" BASIS,
19
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ See the License for the specific language governing permissions and
21
+ limitations under the License.
22
+ */
23
+
24
+ const getFriendlyURL = url => {
25
+ const urlObj = new URL(url, location);
26
+ if (urlObj.origin === location.origin) {
27
+ return urlObj.pathname;
28
+ }
29
+ return urlObj.href;
30
+ };
31
+
32
+ var messages = {
33
+ strategyStart: (strategyName, request) => `Using ${strategyName} to ` + `respond to '${getFriendlyURL(request.url)}'`,
34
+ printFinalResponse: response => {
35
+ if (response) {
36
+ logger_mjs.logger.groupCollapsed(`View the final response here.`);
37
+ logger_mjs.logger.unprefixed.log(response);
38
+ logger_mjs.logger.groupEnd();
39
+ }
40
+ }
41
+ };
42
+
43
+ /*
44
+ Copyright 2018 Google Inc. All Rights Reserved.
45
+ Licensed under the Apache License, Version 2.0 (the "License");
46
+ you may not use this file except in compliance with the License.
47
+ You may obtain a copy of the License at
48
+
49
+ http://www.apache.org/licenses/LICENSE-2.0
50
+
51
+ Unless required by applicable law or agreed to in writing, software
52
+ distributed under the License is distributed on an "AS IS" BASIS,
53
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
54
+ See the License for the specific language governing permissions and
55
+ limitations under the License.
56
+ */
57
+
58
+ /**
59
+ * An implementation of a [cache-first]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network}
60
+ * request strategy.
61
+ *
62
+ * A cache first strategy is useful for assets that have been revisioned,
63
+ * such as URLs like `/styles/example.a8f5f1.css`, since they
64
+ * can be cached for long periods of time.
65
+ *
66
+ * @memberof workbox.strategies
67
+ */
68
+ class CacheFirst {
69
+ /**
70
+ * @param {Object} options
71
+ * @param {string} options.cacheName Cache name to store and retrieve
72
+ * requests. Defaults to cache names provided by
73
+ * [workbox-core]{@link workbox.core.cacheNames}.
74
+ * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
75
+ * to use in conjunction with this caching strategy.
76
+ * @param {Object} options.fetchOptions Values passed along to the
77
+ * [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
78
+ * of all fetch() requests made by this strategy.
79
+ */
80
+ constructor(options = {}) {
81
+ this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
82
+ this._plugins = options.plugins || [];
83
+ this._fetchOptions = options.fetchOptions || null;
84
+ }
85
+
86
+ /**
87
+ * This method will perform a request strategy and follows an API that
88
+ * will work with the
89
+ * [Workbox Router]{@link workbox.routing.Router}.
90
+ *
91
+ * @param {Object} input
92
+ * @param {FetchEvent} input.event The fetch event to run this strategy
93
+ * against.
94
+ * @return {Promise<Response>}
95
+ */
96
+ handle({ event }) {
97
+ var _this = this;
98
+
99
+ return babelHelpers.asyncToGenerator(function* () {
100
+ {
101
+ assert_mjs.assert.isInstance(event, FetchEvent, {
102
+ moduleName: 'workbox-strategies',
103
+ className: 'CacheFirst',
104
+ funcName: 'handle',
105
+ paramName: 'event'
106
+ });
107
+ }
108
+
109
+ return _this.makeRequest({
110
+ event,
111
+ request: event.request
112
+ });
113
+ })();
114
+ }
115
+
116
+ /**
117
+ * This method can be used to perform a make a standalone request outside the
118
+ * context of the [Workbox Router]{@link workbox.routing.Router}.
119
+ *
120
+ * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
121
+ * for more usage information.
122
+ *
123
+ * @param {Object} input
124
+ * @param {Request|string} input.request Either a
125
+ * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
126
+ * object, or a string URL, corresponding to the request to be made.
127
+ * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
128
+ * called automatically to extend the service worker's lifetime.
129
+ * @return {Promise<Response>}
130
+ */
131
+ makeRequest({ event, request }) {
132
+ var _this2 = this;
133
+
134
+ return babelHelpers.asyncToGenerator(function* () {
135
+ const logs = [];
136
+
137
+ if (typeof request === 'string') {
138
+ request = new Request(request);
139
+ }
140
+
141
+ {
142
+ assert_mjs.assert.isInstance(request, Request, {
143
+ moduleName: 'workbox-strategies',
144
+ className: 'CacheFirst',
145
+ funcName: 'makeRequest',
146
+ paramName: 'request'
147
+ });
148
+ }
149
+
150
+ let response = yield cacheWrapper_mjs.cacheWrapper.match(_this2._cacheName, request, null, _this2._plugins);
151
+
152
+ let error;
153
+ if (!response) {
154
+ {
155
+ logs.push(`No response found in the '${_this2._cacheName}' cache. ` + `Will respond with a network request.`);
156
+ }
157
+ try {
158
+ response = yield _this2._getFromNetwork(request, event);
159
+ } catch (err) {
160
+ error = err;
161
+ }
162
+
163
+ {
164
+ if (response) {
165
+ logs.push(`Got response from network.`);
166
+ } else {
167
+ logs.push(`Unable to get a response from the network.`);
168
+ }
169
+ }
170
+ } else {
171
+ {
172
+ logs.push(`Found a cached response in the '${_this2._cacheName}' cache.`);
173
+ }
174
+ }
175
+
176
+ {
177
+ logger_mjs.logger.groupCollapsed(messages.strategyStart('CacheFirst', request));
178
+ for (let log of logs) {
179
+ logger_mjs.logger.log(log);
180
+ }
181
+ messages.printFinalResponse(response);
182
+ logger_mjs.logger.groupEnd();
183
+ }
184
+
185
+ if (error) {
186
+ // Don't swallow error as we'll want it to throw and enable catch
187
+ // handlers in router.
188
+ throw error;
189
+ }
190
+
191
+ return response;
192
+ })();
193
+ }
194
+
195
+ /**
196
+ * Handles the network and cache part of CacheFirst.
197
+ *
198
+ * @param {Request} request
199
+ * @param {FetchEvent} [event]
200
+ * @return {Promise<Response>}
201
+ *
202
+ * @private
203
+ */
204
+ _getFromNetwork(request, event) {
205
+ var _this3 = this;
206
+
207
+ return babelHelpers.asyncToGenerator(function* () {
208
+ const response = yield fetchWrapper_mjs.fetchWrapper.fetch(request, _this3._fetchOptions, _this3._plugins);
209
+
210
+ // Keep the service worker while we put the request to the cache
211
+ const responseClone = response.clone();
212
+ const cachePutPromise = cacheWrapper_mjs.cacheWrapper.put(_this3._cacheName, request, responseClone, _this3._plugins);
213
+
214
+ if (event) {
215
+ try {
216
+ event.waitUntil(cachePutPromise);
217
+ } catch (error) {
218
+ {
219
+ logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
220
+ }
221
+ }
222
+ }
223
+
224
+ return response;
225
+ })();
226
+ }
227
+ }
228
+
229
+ /*
230
+ Copyright 2018 Google Inc. All Rights Reserved.
231
+ Licensed under the Apache License, Version 2.0 (the "License");
232
+ you may not use this file except in compliance with the License.
233
+ You may obtain a copy of the License at
234
+
235
+ http://www.apache.org/licenses/LICENSE-2.0
236
+
237
+ Unless required by applicable law or agreed to in writing, software
238
+ distributed under the License is distributed on an "AS IS" BASIS,
239
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
240
+ See the License for the specific language governing permissions and
241
+ limitations under the License.
242
+ */
243
+
244
+ /**
245
+ * An implementation of a
246
+ * [cache-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-only}
247
+ * request strategy.
248
+ *
249
+ * This class is useful if you want to take advantage of any [Workbox plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}.
250
+ *
251
+ * @memberof workbox.strategies
252
+ */
253
+ class CacheOnly {
254
+ /**
255
+ * @param {Object} options
256
+ * @param {string} options.cacheName Cache name to store and retrieve
257
+ * requests. Defaults to cache names provided by
258
+ * [workbox-core]{@link workbox.core.cacheNames}.
259
+ * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
260
+ * to use in conjunction with this caching strategy.
261
+ */
262
+ constructor(options = {}) {
263
+ this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
264
+ this._plugins = options.plugins || [];
265
+ }
266
+
267
+ /**
268
+ * This method will perform a request strategy and follows an API that
269
+ * will work with the
270
+ * [Workbox Router]{@link workbox.routing.Router}.
271
+ *
272
+ * @param {Object} input
273
+ * @param {FetchEvent} input.event The fetch event to run this strategy
274
+ * against.
275
+ * @return {Promise<Response>}
276
+ */
277
+ handle({ event }) {
278
+ var _this = this;
279
+
280
+ return babelHelpers.asyncToGenerator(function* () {
281
+ {
282
+ assert_mjs.assert.isInstance(event, FetchEvent, {
283
+ moduleName: 'workbox-strategies',
284
+ className: 'CacheOnly',
285
+ funcName: 'handle',
286
+ paramName: 'event'
287
+ });
288
+ }
289
+
290
+ return _this.makeRequest({
291
+ event,
292
+ request: event.request
293
+ });
294
+ })();
295
+ }
296
+
297
+ /**
298
+ * This method can be used to perform a make a standalone request outside the
299
+ * context of the [Workbox Router]{@link workbox.routing.Router}.
300
+ *
301
+ * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
302
+ * for more usage information.
303
+ *
304
+ * @param {Object} input
305
+ * @param {Request|string} input.request Either a
306
+ * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
307
+ * object, or a string URL, corresponding to the request to be made.
308
+ * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
309
+ * called automatically to extend the service worker's lifetime.
310
+ * @return {Promise<Response>}
311
+ */
312
+ makeRequest({ event, request }) {
313
+ var _this2 = this;
314
+
315
+ return babelHelpers.asyncToGenerator(function* () {
316
+ if (typeof request === 'string') {
317
+ request = new Request(request);
318
+ }
319
+
320
+ {
321
+ assert_mjs.assert.isInstance(request, Request, {
322
+ moduleName: 'workbox-strategies',
323
+ className: 'CacheOnly',
324
+ funcName: 'makeRequest',
325
+ paramName: 'request'
326
+ });
327
+ }
328
+
329
+ const response = yield cacheWrapper_mjs.cacheWrapper.match(_this2._cacheName, request, null, _this2._plugins);
330
+
331
+ {
332
+ logger_mjs.logger.groupCollapsed(messages.strategyStart('CacheOnly', request));
333
+ if (response) {
334
+ logger_mjs.logger.log(`Found a cached response in the '${_this2._cacheName}'` + ` cache.`);
335
+ messages.printFinalResponse(response);
336
+ } else {
337
+ logger_mjs.logger.log(`No response found in the '${_this2._cacheName}' cache.`);
338
+ }
339
+ logger_mjs.logger.groupEnd();
340
+ }
341
+
342
+ return response;
343
+ })();
344
+ }
345
+ }
346
+
347
+ /*
348
+ Copyright 2016 Google Inc. All Rights Reserved.
349
+ Licensed under the Apache License, Version 2.0 (the "License");
350
+ you may not use this file except in compliance with the License.
351
+ You may obtain a copy of the License at
352
+
353
+ http://www.apache.org/licenses/LICENSE-2.0
354
+
355
+ Unless required by applicable law or agreed to in writing, software
356
+ distributed under the License is distributed on an "AS IS" BASIS,
357
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
358
+ See the License for the specific language governing permissions and
359
+ limitations under the License.
360
+ */
361
+
362
+ var cacheOkAndOpaquePlugin = {
363
+ /**
364
+ * Return return a response (i.e. allow caching) if the
365
+ * response is ok (i.e. 200) or is opaque.
366
+ *
367
+ * @param {Object} input
368
+ * @param {Response} input.response
369
+ * @return {Response|null}
370
+ *
371
+ * @private
372
+ */
373
+ cacheWillUpdate: ({ response }) => {
374
+ if (response.ok || response.status === 0) {
375
+ return response;
376
+ }
377
+ return null;
378
+ }
379
+ };
380
+
381
+ /*
382
+ Copyright 2018 Google Inc. All Rights Reserved.
383
+ Licensed under the Apache License, Version 2.0 (the "License");
384
+ you may not use this file except in compliance with the License.
385
+ You may obtain a copy of the License at
386
+
387
+ http://www.apache.org/licenses/LICENSE-2.0
388
+
389
+ Unless required by applicable law or agreed to in writing, software
390
+ distributed under the License is distributed on an "AS IS" BASIS,
391
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
392
+ See the License for the specific language governing permissions and
393
+ limitations under the License.
394
+ */
395
+
396
+ /**
397
+ * An implementation of a
398
+ * [network first]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-falling-back-to-cache}
399
+ * request strategy.
400
+ *
401
+ * By default, this strategy will cache responses with a 200 status code as
402
+ * well as [opaque responses]{@link https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests}.
403
+ * Opaque responses are are cross-origin requests where the response doesn't
404
+ * support [CORS]{@link https://enable-cors.org/}.
405
+ *
406
+ * @memberof workbox.strategies
407
+ */
408
+ class NetworkFirst {
409
+ /**
410
+ * @param {Object} options
411
+ * @param {string} options.cacheName Cache name to store and retrieve
412
+ * requests. Defaults to cache names provided by
413
+ * [workbox-core]{@link workbox.core.cacheNames}.
414
+ * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
415
+ * to use in conjunction with this caching strategy.
416
+ * @param {Object} options.fetchOptions Values passed along to the
417
+ * [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
418
+ * of all fetch() requests made by this strategy.
419
+ * @param {number} options.networkTimeoutSeconds If set, any network requests
420
+ * that fail to respond within the timeout will fallback to the cache.
421
+ *
422
+ * This option can be used to combat
423
+ * "[lie-fi]{@link https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi}"
424
+ * scenarios.
425
+ */
426
+ constructor(options = {}) {
427
+ this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
428
+
429
+ if (options.plugins) {
430
+ let isUsingCacheWillUpdate = options.plugins.some(plugin => !!plugin.cacheWillUpdate);
431
+ this._plugins = isUsingCacheWillUpdate ? options.plugins : [cacheOkAndOpaquePlugin, ...options.plugins];
432
+ } else {
433
+ // No plugins passed in, use the default plugin.
434
+ this._plugins = [cacheOkAndOpaquePlugin];
435
+ }
436
+
437
+ this._networkTimeoutSeconds = options.networkTimeoutSeconds;
438
+ {
439
+ if (this._networkTimeoutSeconds) {
440
+ assert_mjs.assert.isType(this._networkTimeoutSeconds, 'number', {
441
+ moduleName: 'workbox-strategies',
442
+ className: 'NetworkFirst',
443
+ funcName: 'constructor',
444
+ paramName: 'networkTimeoutSeconds'
445
+ });
446
+ }
447
+ }
448
+
449
+ this._fetchOptions = options.fetchOptions || null;
450
+ }
451
+
452
+ /**
453
+ * This method will perform a request strategy and follows an API that
454
+ * will work with the
455
+ * [Workbox Router]{@link workbox.routing.Router}.
456
+ *
457
+ * @param {Object} input
458
+ * @param {FetchEvent} input.event The fetch event to run this strategy
459
+ * against.
460
+ * @return {Promise<Response>}
461
+ */
462
+ handle({ event }) {
463
+ var _this = this;
464
+
465
+ return babelHelpers.asyncToGenerator(function* () {
466
+ {
467
+ assert_mjs.assert.isInstance(event, FetchEvent, {
468
+ moduleName: 'workbox-strategies',
469
+ className: 'NetworkFirst',
470
+ funcName: 'handle',
471
+ paramName: 'event'
472
+ });
473
+ }
474
+
475
+ return _this.makeRequest({
476
+ event,
477
+ request: event.request
478
+ });
479
+ })();
480
+ }
481
+
482
+ /**
483
+ * This method can be used to perform a make a standalone request outside the
484
+ * context of the [Workbox Router]{@link workbox.routing.Router}.
485
+ *
486
+ * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
487
+ * for more usage information.
488
+ *
489
+ * @param {Object} input
490
+ * @param {Request|string} input.request Either a
491
+ * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
492
+ * object, or a string URL, corresponding to the request to be made.
493
+ * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
494
+ * called automatically to extend the service worker's lifetime.
495
+ * @return {Promise<Response>}
496
+ */
497
+ makeRequest({ event, request }) {
498
+ var _this2 = this;
499
+
500
+ return babelHelpers.asyncToGenerator(function* () {
501
+ const logs = [];
502
+
503
+ if (typeof request === 'string') {
504
+ request = new Request(request);
505
+ }
506
+
507
+ {
508
+ assert_mjs.assert.isInstance(request, Request, {
509
+ moduleName: 'workbox-strategies',
510
+ className: 'NetworkFirst',
511
+ funcName: 'handle',
512
+ paramName: 'makeRequest'
513
+ });
514
+ }
515
+
516
+ const promises = [];
517
+ let timeoutId;
518
+
519
+ if (_this2._networkTimeoutSeconds) {
520
+ const { id, promise } = _this2._getTimeoutPromise(request, logs);
521
+ timeoutId = id;
522
+ promises.push(promise);
523
+ }
524
+
525
+ const networkPromise = _this2._getNetworkPromise(timeoutId, event, request, logs);
526
+ promises.push(networkPromise);
527
+
528
+ // Promise.race() will resolve as soon as the first promise resolves.
529
+ let response = yield Promise.race(promises);
530
+ // If Promise.race() resolved with null, it might be due to a network
531
+ // timeout + a cache miss. If that were to happen, we'd rather wait until
532
+ // the networkPromise resolves instead of returning null.
533
+ // Note that it's fine to await an already-resolved promise, so we don't
534
+ // have to check to see if it's still "in flight".
535
+ if (!response) {
536
+ response = yield networkPromise;
537
+ }
538
+
539
+ {
540
+ logger_mjs.logger.groupCollapsed(messages.strategyStart('NetworkFirst', request));
541
+ for (let log of logs) {
542
+ logger_mjs.logger.log(log);
543
+ }
544
+ messages.printFinalResponse(response);
545
+ logger_mjs.logger.groupEnd();
546
+ }
547
+
548
+ return response;
549
+ })();
550
+ }
551
+
552
+ /**
553
+ * @param {Request} request
554
+ * @param {Array} logs A reference to the logs array
555
+ * @return {Promise<Response>}
556
+ *
557
+ * @private
558
+ */
559
+ _getTimeoutPromise(request, logs) {
560
+ var _this3 = this;
561
+
562
+ let timeoutId;
563
+ const timeoutPromise = new Promise(resolve => {
564
+ const onNetworkTimeout = (() => {
565
+ var _ref = babelHelpers.asyncToGenerator(function* () {
566
+ {
567
+ logs.push(`Timing out the network response at ` + `${_this3._networkTimeoutSeconds} seconds.`);
568
+ }
569
+
570
+ resolve((yield _this3._respondFromCache(request)));
571
+ });
572
+
573
+ return function onNetworkTimeout() {
574
+ return _ref.apply(this, arguments);
575
+ };
576
+ })();
577
+
578
+ timeoutId = setTimeout(onNetworkTimeout, this._networkTimeoutSeconds * 1000);
579
+ });
580
+
581
+ return {
582
+ promise: timeoutPromise,
583
+ id: timeoutId
584
+ };
585
+ }
586
+
587
+ /**
588
+ * @param {number} timeoutId
589
+ * @param {FetchEvent|null} event
590
+ * @param {Request} request
591
+ * @param {Array} logs A reference to the logs Array.
592
+ * @return {Promise<Response>}
593
+ *
594
+ * @private
595
+ */
596
+ _getNetworkPromise(timeoutId, event, request, logs) {
597
+ var _this4 = this;
598
+
599
+ return babelHelpers.asyncToGenerator(function* () {
600
+ let error;
601
+ let response;
602
+ try {
603
+ response = yield fetchWrapper_mjs.fetchWrapper.fetch(request, _this4._fetchOptions, _this4._plugins);
604
+ } catch (err) {
605
+ error = err;
606
+ }
607
+
608
+ if (timeoutId) {
609
+ clearTimeout(timeoutId);
610
+ }
611
+
612
+ {
613
+ if (response) {
614
+ logs.push(`Got response from network.`);
615
+ } else {
616
+ logs.push(`Unable to get a response from the network. Will respond ` + `with a cached response.`);
617
+ }
618
+ }
619
+
620
+ if (error || !response) {
621
+ response = yield _this4._respondFromCache(request);
622
+ {
623
+ if (response) {
624
+ logs.push(`Found a cached response in the '${_this4._cacheName}'` + ` cache.`);
625
+ } else {
626
+ logs.push(`No response found in the '${_this4._cacheName}' cache.`);
627
+ }
628
+ }
629
+ } else {
630
+ // Keep the service worker alive while we put the request in the cache
631
+ const responseClone = response.clone();
632
+ const cachePut = cacheWrapper_mjs.cacheWrapper.put(_this4._cacheName, request, responseClone, _this4._plugins);
633
+
634
+ if (event) {
635
+ try {
636
+ // The event has been responded to so we can keep the SW alive to
637
+ // respond to the request
638
+ event.waitUntil(cachePut);
639
+ } catch (err) {
640
+ {
641
+ logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
642
+ }
643
+ }
644
+ }
645
+ }
646
+
647
+ return response;
648
+ })();
649
+ }
650
+
651
+ /**
652
+ * Used if the network timeouts or fails to make the request.
653
+ *
654
+ * @param {Request} request The fetchEvent request to match in the cache
655
+ * @return {Promise<Object>}
656
+ *
657
+ * @private
658
+ */
659
+ _respondFromCache(request) {
660
+ return cacheWrapper_mjs.cacheWrapper.match(this._cacheName, request, null, this._plugins);
661
+ }
662
+ }
663
+
664
+ /*
665
+ Copyright 2018 Google Inc. All Rights Reserved.
666
+ Licensed under the Apache License, Version 2.0 (the "License");
667
+ you may not use this file except in compliance with the License.
668
+ You may obtain a copy of the License at
669
+
670
+ http://www.apache.org/licenses/LICENSE-2.0
671
+
672
+ Unless required by applicable law or agreed to in writing, software
673
+ distributed under the License is distributed on an "AS IS" BASIS,
674
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
675
+ See the License for the specific language governing permissions and
676
+ limitations under the License.
677
+ */
678
+
679
+ /**
680
+ * An implementation of a
681
+ * [network-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-only}
682
+ * request strategy.
683
+ *
684
+ * This class is useful if you want to take advantage of any [Workbox plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}.
685
+ *
686
+ * @memberof workbox.strategies
687
+ */
688
+ class NetworkOnly {
689
+ /**
690
+ * @param {Object} options
691
+ * @param {string} options.cacheName Cache name to store and retrieve
692
+ * requests. Defaults to cache names provided by
693
+ * [workbox-core]{@link workbox.core.cacheNames}.
694
+ * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
695
+ * to use in conjunction with this caching strategy.
696
+ * @param {Object} options.fetchOptions Values passed along to the
697
+ * [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
698
+ * of all fetch() requests made by this strategy.
699
+ */
700
+ constructor(options = {}) {
701
+ this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
702
+ this._plugins = options.plugins || [];
703
+ this._fetchOptions = options.fetchOptions || null;
704
+ }
705
+
706
+ /**
707
+ * This method will perform a request strategy and follows an API that
708
+ * will work with the
709
+ * [Workbox Router]{@link workbox.routing.Router}.
710
+ *
711
+ * @param {Object} input
712
+ * @param {FetchEvent} input.event The fetch event to run this strategy
713
+ * against.
714
+ * @return {Promise<Response>}
715
+ */
716
+ handle({ event }) {
717
+ var _this = this;
718
+
719
+ return babelHelpers.asyncToGenerator(function* () {
720
+ {
721
+ assert_mjs.assert.isInstance(event, FetchEvent, {
722
+ moduleName: 'workbox-strategies',
723
+ className: 'NetworkOnly',
724
+ funcName: 'handle',
725
+ paramName: 'event'
726
+ });
727
+ }
728
+
729
+ return _this.makeRequest({
730
+ event,
731
+ request: event.request
732
+ });
733
+ })();
734
+ }
735
+
736
+ /**
737
+ * This method can be used to perform a make a standalone request outside the
738
+ * context of the [Workbox Router]{@link workbox.routing.Router}.
739
+ *
740
+ * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
741
+ * for more usage information.
742
+ *
743
+ * @param {Object} input
744
+ * @param {Request|string} input.request Either a
745
+ * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
746
+ * object, or a string URL, corresponding to the request to be made.
747
+ * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
748
+ * called automatically to extend the service worker's lifetime.
749
+ * @return {Promise<Response>}
750
+ */
751
+ makeRequest({ event, request }) {
752
+ var _this2 = this;
753
+
754
+ return babelHelpers.asyncToGenerator(function* () {
755
+ if (typeof request === 'string') {
756
+ request = new Request(request);
757
+ }
758
+
759
+ {
760
+ assert_mjs.assert.isInstance(request, Request, {
761
+ moduleName: 'workbox-strategies',
762
+ className: 'NetworkOnly',
763
+ funcName: 'handle',
764
+ paramName: 'request'
765
+ });
766
+ }
767
+
768
+ let error;
769
+ let response;
770
+ try {
771
+ response = yield fetchWrapper_mjs.fetchWrapper.fetch(request, _this2._fetchOptions, _this2._plugins);
772
+ } catch (err) {
773
+ error = err;
774
+ }
775
+
776
+ {
777
+ logger_mjs.logger.groupCollapsed(messages.strategyStart('NetworkOnly', request));
778
+ if (response) {
779
+ logger_mjs.logger.log(`Got response from network.`);
780
+ } else {
781
+ logger_mjs.logger.log(`Unable to get a response from the network.`);
782
+ }
783
+ messages.printFinalResponse(response);
784
+ logger_mjs.logger.groupEnd();
785
+ }
786
+
787
+ // If there was an error thrown, re-throw it to ensure the Routers
788
+ // catch handler is triggered.
789
+ if (error) {
790
+ throw error;
791
+ }
792
+
793
+ return response;
794
+ })();
795
+ }
796
+ }
797
+
798
+ /*
799
+ Copyright 2018 Google Inc. All Rights Reserved.
800
+ Licensed under the Apache License, Version 2.0 (the "License");
801
+ you may not use this file except in compliance with the License.
802
+ You may obtain a copy of the License at
803
+
804
+ http://www.apache.org/licenses/LICENSE-2.0
805
+
806
+ Unless required by applicable law or agreed to in writing, software
807
+ distributed under the License is distributed on an "AS IS" BASIS,
808
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
809
+ See the License for the specific language governing permissions and
810
+ limitations under the License.
811
+ */
812
+
813
+ /**
814
+ * An implementation of a
815
+ * [stale-while-revalidate]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#stale-while-revalidate}
816
+ * request strategy.
817
+ *
818
+ * Resources are requested from both the cache and the network in parallel.
819
+ * The strategy will respond with the cached version if available, otherwise
820
+ * wait for the network response. The cache is updated with the network response
821
+ * with each successful request.
822
+ *
823
+ * By default, this strategy will cache responses with a 200 status code as
824
+ * well as [opaque responses]{@link https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests}.
825
+ * Opaque responses are are cross-origin requests where the response doesn't
826
+ * support [CORS]{@link https://enable-cors.org/}.
827
+ *
828
+ * @memberof workbox.strategies
829
+ */
830
+ class StaleWhileRevalidate {
831
+ /**
832
+ * @param {Object} options
833
+ * @param {string} options.cacheName Cache name to store and retrieve
834
+ * requests. Defaults to cache names provided by
835
+ * [workbox-core]{@link workbox.core.cacheNames}.
836
+ * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
837
+ * to use in conjunction with this caching strategy.
838
+ * @param {Object} options.fetchOptions Values passed along to the
839
+ * [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
840
+ * of all fetch() requests made by this strategy.
841
+ */
842
+ constructor(options = {}) {
843
+ this._cacheName = cacheNames_mjs.cacheNames.getRuntimeName(options.cacheName);
844
+ this._plugins = options.plugins || [];
845
+
846
+ if (options.plugins) {
847
+ let isUsingCacheWillUpdate = options.plugins.some(plugin => !!plugin.cacheWillUpdate);
848
+ this._plugins = isUsingCacheWillUpdate ? options.plugins : [cacheOkAndOpaquePlugin, ...options.plugins];
849
+ } else {
850
+ // No plugins passed in, use the default plugin.
851
+ this._plugins = [cacheOkAndOpaquePlugin];
852
+ }
853
+
854
+ this._fetchOptions = options.fetchOptions || null;
855
+ }
856
+
857
+ /**
858
+ * This method will perform a request strategy and follows an API that
859
+ * will work with the
860
+ * [Workbox Router]{@link workbox.routing.Router}.
861
+ *
862
+ * @param {Object} input
863
+ * @param {FetchEvent} input.event The fetch event to run this strategy
864
+ * against.
865
+ * @return {Promise<Response>}
866
+ */
867
+ handle({ event }) {
868
+ var _this = this;
869
+
870
+ return babelHelpers.asyncToGenerator(function* () {
871
+ {
872
+ assert_mjs.assert.isInstance(event, FetchEvent, {
873
+ moduleName: 'workbox-strategies',
874
+ className: 'StaleWhileRevalidate',
875
+ funcName: 'handle',
876
+ paramName: 'event'
877
+ });
878
+ }
879
+
880
+ return _this.makeRequest({
881
+ event,
882
+ request: event.request
883
+ });
884
+ })();
885
+ }
886
+
887
+ /**
888
+ * This method can be used to perform a make a standalone request outside the
889
+ * context of the [Workbox Router]{@link workbox.routing.Router}.
890
+ *
891
+ * See "[Advanced Recipes](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#make-requests)"
892
+ * for more usage information.
893
+ *
894
+ * @param {Object} input
895
+ * @param {Request|string} input.request Either a
896
+ * [`Request`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Request}
897
+ * object, or a string URL, corresponding to the request to be made.
898
+ * @param {FetchEvent} [input.event] If provided, `event.waitUntil()` will be
899
+ * called automatically to extend the service worker's lifetime.
900
+ * @return {Promise<Response>}
901
+ */
902
+ makeRequest({ event, request }) {
903
+ var _this2 = this;
904
+
905
+ return babelHelpers.asyncToGenerator(function* () {
906
+ const logs = [];
907
+
908
+ if (typeof request === 'string') {
909
+ request = new Request(request);
910
+ }
911
+
912
+ {
913
+ assert_mjs.assert.isInstance(request, Request, {
914
+ moduleName: 'workbox-strategies',
915
+ className: 'StaleWhileRevalidate',
916
+ funcName: 'handle',
917
+ paramName: 'request'
918
+ });
919
+ }
920
+
921
+ const fetchAndCachePromise = _this2._getFromNetwork(request, event);
922
+
923
+ let response = yield cacheWrapper_mjs.cacheWrapper.match(_this2._cacheName, request, null, _this2._plugins);
924
+
925
+ if (response) {
926
+ {
927
+ logs.push(`Found a cached response in the '${_this2._cacheName}'` + ` cache. Will update with the network response in the background.`);
928
+ }
929
+
930
+ if (event) {
931
+ try {
932
+ event.waitUntil(fetchAndCachePromise);
933
+ } catch (error) {
934
+ {
935
+ logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
936
+ }
937
+ }
938
+ }
939
+ } else {
940
+ {
941
+ logs.push(`No response found in the '${_this2._cacheName}' cache. ` + `Will wait for the network response.`);
942
+ }
943
+ response = yield fetchAndCachePromise;
944
+ }
945
+
946
+ {
947
+ logger_mjs.logger.groupCollapsed(messages.strategyStart('StaleWhileRevalidate', request));
948
+ for (let log of logs) {
949
+ logger_mjs.logger.log(log);
950
+ }
951
+ messages.printFinalResponse(response);
952
+ logger_mjs.logger.groupEnd();
953
+ }
954
+
955
+ return response;
956
+ })();
957
+ }
958
+
959
+ /**
960
+ * @param {Request} request
961
+ * @param {FetchEvent} [event]
962
+ * @return {Promise<Response>}
963
+ *
964
+ * @private
965
+ */
966
+ _getFromNetwork(request, event) {
967
+ var _this3 = this;
968
+
969
+ return babelHelpers.asyncToGenerator(function* () {
970
+ const response = yield fetchWrapper_mjs.fetchWrapper.fetch(request, _this3._fetchOptions, _this3._plugins);
971
+
972
+ const cachePutPromise = cacheWrapper_mjs.cacheWrapper.put(_this3._cacheName, request, response.clone(), _this3._plugins);
973
+
974
+ if (event) {
975
+ try {
976
+ event.waitUntil(cachePutPromise);
977
+ } catch (error) {
978
+ {
979
+ logger_mjs.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
980
+ }
981
+ }
982
+ }
983
+
984
+ return response;
985
+ })();
986
+ }
987
+ }
988
+
989
+ /*
990
+ Copyright 2017 Google Inc.
991
+
992
+ Licensed under the Apache License, Version 2.0 (the "License");
993
+ you may not use this file except in compliance with the License.
994
+ You may obtain a copy of the License at
995
+
996
+ https://www.apache.org/licenses/LICENSE-2.0
997
+
998
+ Unless required by applicable law or agreed to in writing, software
999
+ distributed under the License is distributed on an "AS IS" BASIS,
1000
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1001
+ See the License for the specific language governing permissions and
1002
+ limitations under the License.
1003
+ */
1004
+
1005
+ var publicAPI = /*#__PURE__*/Object.freeze({
1006
+ CacheFirst: CacheFirst,
1007
+ CacheOnly: CacheOnly,
1008
+ NetworkFirst: NetworkFirst,
1009
+ NetworkOnly: NetworkOnly,
1010
+ StaleWhileRevalidate: StaleWhileRevalidate
1011
+ });
1012
+
1013
+ /*
1014
+ Copyright 2016 Google Inc. All Rights Reserved.
1015
+ Licensed under the Apache License, Version 2.0 (the "License");
1016
+ you may not use this file except in compliance with the License.
1017
+ You may obtain a copy of the License at
1018
+
1019
+ http://www.apache.org/licenses/LICENSE-2.0
1020
+
1021
+ Unless required by applicable law or agreed to in writing, software
1022
+ distributed under the License is distributed on an "AS IS" BASIS,
1023
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1024
+ See the License for the specific language governing permissions and
1025
+ limitations under the License.
1026
+ */
1027
+
1028
+ /**
1029
+ * @function workbox.strategies.cacheFirst
1030
+ * @param {workbox.strategies.StrategyOptions} options
1031
+ */
1032
+
1033
+ /**
1034
+ * @function workbox.strategies.cacheOnly
1035
+ * @param {workbox.strategies.StrategyOptions} options
1036
+ */
1037
+
1038
+ /**
1039
+ * @function workbox.strategies.networkFirst
1040
+ * @param {workbox.strategies.StrategyOptions} options
1041
+ */
1042
+
1043
+ /**
1044
+ * @function workbox.strategies.networkOnly
1045
+ * @param {workbox.strategies.StrategyOptions} options
1046
+ */
1047
+
1048
+ /**
1049
+ * @function workbox.strategies.staleWhileRevalidate
1050
+ * @param {workbox.strategies.StrategyOptions} options
1051
+ */
1052
+
1053
+ const mapping = {
1054
+ cacheFirst: CacheFirst,
1055
+ cacheOnly: CacheOnly,
1056
+ networkFirst: NetworkFirst,
1057
+ networkOnly: NetworkOnly,
1058
+ staleWhileRevalidate: StaleWhileRevalidate
1059
+ };
1060
+
1061
+ const defaultExport = {};
1062
+ Object.keys(mapping).forEach(keyName => {
1063
+ defaultExport[keyName] = (options = {}) => {
1064
+ const StrategyClass = mapping[keyName];
1065
+ return new StrategyClass(Object.assign(options));
1066
+ };
1067
+ });
1068
+
1069
+ /*
1070
+ Copyright 2017 Google Inc.
1071
+
1072
+ Licensed under the Apache License, Version 2.0 (the "License");
1073
+ you may not use this file except in compliance with the License.
1074
+ You may obtain a copy of the License at
1075
+
1076
+ https://www.apache.org/licenses/LICENSE-2.0
1077
+
1078
+ Unless required by applicable law or agreed to in writing, software
1079
+ distributed under the License is distributed on an "AS IS" BASIS,
1080
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1081
+ See the License for the specific language governing permissions and
1082
+ limitations under the License.
1083
+ */
1084
+
1085
+ const finalExport = Object.assign(defaultExport, publicAPI);
1086
+
1087
+ return finalExport;
1088
+
1089
+ }(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private));
1090
+
1091
+ //# sourceMappingURL=workbox-strategies.dev.js.map