files/en-us/web/api/navigationpreloadmanager/enable/index.md
{{APIRef("Service Workers API")}}{{SecureContext_Header}}{{AvailableInWorkers}}
The enable() method of the {{domxref("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.
enable()
None.
A {{jsxref("Promise")}} that resolves with {{jsxref('undefined')}}.
InvalidStateError {{domxref("DOMException")}}
The code below shows how to enable preloading, after first using {{domxref("ServiceWorkerRegistration.navigationPreload")}} to test that it is supported.
addEventListener("activate", (event) => {
event.waitUntil(
(async () => {
if (self.registration.navigationPreload) {
// Enable navigation preloads!
await self.registration.navigationPreload.enable();
}
})(),
);
});
{{Specifications}}
{{Compat}}
{{domxref("NavigationPreloadManager.disable()")}}