dom / latest / navigationpreloadmanager / enable.html /

NavigationPreloadManager.enable()

The enable() method of the NavigationPreloadManager interface is used to enable preloading of resources managed by the service worker. It returns a promise that resolves with undefined.

The method should be called in the service worker's activate event handler, which ensures it is called before any fetch event handler can fire.

Syntax

enable()

Return value

A Promise that resolves with undefined.

Exceptions

InvalidStateError DOMException

There is no active worker associated with the registration to which this NavigationPreloadManager belongs.

Examples

The code below shows how to enable preloading, after first using ServiceWorkerRegistration.navigationPreload to test that it is supported.

addEventListener('activate', event => {
  event.waitUntil(async function() {
    if (self.registration.navigationPreload) {
      // Enable navigation preloads!
      await self.registration.navigationPreload.enable();
    }
  }());
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
enable
59
18
97
preview
No
46
15.4
59
59
No
43
15.4
7.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/NavigationPreloadManager/enable