Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. NavigationPreloadManager
  4. setHeaderValue()

NavigationPreloadManager: setHeaderValue() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨April 2022⁩.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is available inWeb Workers.

ThesetHeaderValue() method of theNavigationPreloadManager interface sets the value of theService-Worker-Navigation-Preload header that will be sent with requests resulting from afetch() operation made during service worker navigation preloading.It returns an emptyPromise that resolves withundefined.

The presence of theService-Worker-Navigation-Preload header in preloading requests allows servers to configure the returned resource differently for preloading fetch requests than from normal fetch requests.The default directive is set totrue: this method allows the possibility of configuring multiple different responses to preload requests.

Note:If a different response may result from setting this header, the server must setVary: Service-Worker-Navigation-Preload to ensure that the different responses are cached.

Syntax

js
setHeaderValue(value)

Parameters

value

An arbitrary string value, which the target server uses to determine what should returned for the requested resource.

Return value

APromise that resolves withundefined.

Exceptions

InvalidStateErrorDOMException

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

Examples

The code below demonstrates how the value might be set.

js
navigator.serviceWorker.ready  .then((registration) =>    registration.navigationPreload.setHeaderValue(newValue),  )  .then(() => console.log("Done!"))  .catch((e) =>    console.error(`NavigationPreloadManager not supported: ${e.message}`),  );

Specifications

Specification
Service Workers Nightly
# dom-navigationpreloadmanager-setheadervalue

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp