source: frontend/node_modules/workbox-navigation-preload/src/enable.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 Copyright 2018 Google LLC
3
4 Use of this source code is governed by an MIT-style
5 license that can be found in the LICENSE file or at
6 https://opensource.org/licenses/MIT.
7*/
8
9import {logger} from 'workbox-core/_private/logger.js';
10import {isSupported} from './isSupported.js';
11import './_version.js';
12
13// Give TypeScript the correct global.
14declare let self: ServiceWorkerGlobalScope;
15
16/**
17 * If the browser supports Navigation Preload, then this will enable it.
18 *
19 * @param {string} [headerValue] Optionally, allows developers to
20 * [override](https://developers.google.com/web/updates/2017/02/navigation-preload#changing_the_header)
21 * the value of the `Service-Worker-Navigation-Preload` header which will be
22 * sent to the server when making the navigation request.
23 *
24 * @memberof workbox-navigation-preload
25 */
26function enable(headerValue?: string): void {
27 if (isSupported()) {
28 self.addEventListener('activate', (event: ExtendableEvent) => {
29 event.waitUntil(
30 self.registration.navigationPreload.enable().then(() => {
31 // Defaults to Service-Worker-Navigation-Preload: true if not set.
32 if (headerValue) {
33 void self.registration.navigationPreload.setHeaderValue(
34 headerValue,
35 );
36 }
37
38 if (process.env.NODE_ENV !== 'production') {
39 logger.log(`Navigation preload is enabled.`);
40 }
41 }),
42 );
43 });
44 } else {
45 if (process.env.NODE_ENV !== 'production') {
46 logger.log(`Navigation preload is not supported in this browser.`);
47 }
48 }
49}
50
51export {enable};
Note: See TracBrowser for help on using the repository browser.