UNPKG

3.06 kBJavaScriptView Raw
1this.workbox = this.workbox || {};
2this.workbox.navigationPreload = (function (exports, logger_mjs) {
3 'use strict';
4
5 try {
6 self['workbox:navigation-preload:4.1.1'] && _();
7 } catch (e) {} // eslint-disable-line
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 * @return {boolean} Whether or not the current browser supports enabling
18 * navigation preload.
19 *
20 * @memberof workbox.navigationPreload
21 */
22
23 function isSupported() {
24 return Boolean(self.registration && self.registration.navigationPreload);
25 }
26
27 /*
28 Copyright 2018 Google LLC
29
30 Use of this source code is governed by an MIT-style
31 license that can be found in the LICENSE file or at
32 https://opensource.org/licenses/MIT.
33 */
34 /**
35 * If the browser supports Navigation Preload, then this will disable it.
36 *
37 * @memberof workbox.navigationPreload
38 */
39
40 function disable() {
41 if (isSupported()) {
42 self.addEventListener('activate', event => {
43 event.waitUntil(self.registration.navigationPreload.disable().then(() => {
44 {
45 logger_mjs.logger.log(`Navigation preload is disabled.`);
46 }
47 }));
48 });
49 } else {
50 {
51 logger_mjs.logger.log(`Navigation preload is not supported in this browser.`);
52 }
53 }
54 }
55
56 /*
57 Copyright 2018 Google LLC
58
59 Use of this source code is governed by an MIT-style
60 license that can be found in the LICENSE file or at
61 https://opensource.org/licenses/MIT.
62 */
63 /**
64 * If the browser supports Navigation Preload, then this will enable it.
65 *
66 * @param {string} [headerValue] Optionally, allows developers to
67 * [override](https://developers.google.com/web/updates/2017/02/navigation-preload#changing_the_header)
68 * the value of the `Service-Worker-Navigation-Preload` header which will be
69 * sent to the server when making the navigation request.
70 *
71 * @memberof workbox.navigationPreload
72 */
73
74 function enable(headerValue) {
75 if (isSupported()) {
76 self.addEventListener('activate', event => {
77 event.waitUntil(self.registration.navigationPreload.enable().then(() => {
78 // Defaults to Service-Worker-Navigation-Preload: true if not set.
79 if (headerValue) {
80 self.registration.navigationPreload.setHeaderValue(headerValue);
81 }
82
83 {
84 logger_mjs.logger.log(`Navigation preload is enabled.`);
85 }
86 }));
87 });
88 } else {
89 {
90 logger_mjs.logger.log(`Navigation preload is not supported in this browser.`);
91 }
92 }
93 }
94
95 /*
96 Copyright 2018 Google LLC
97
98 Use of this source code is governed by an MIT-style
99 license that can be found in the LICENSE file or at
100 https://opensource.org/licenses/MIT.
101 */
102
103 exports.disable = disable;
104 exports.enable = enable;
105 exports.isSupported = isSupported;
106
107 return exports;
108
109}({}, workbox.core._private));
110