Back to Content

Service-Worker-Navigation-Preload header

files/en-us/web/http/reference/headers/service-worker-navigation-preload/index.md

latest2.0 KB
Original Source

The HTTP Service-Worker-Navigation-Preload {{Glossary("request header")}} indicates that the request was the result of a {{domxref("Window/fetch", "fetch()")}} operation made during service worker navigation preloading. It allows a server to respond with a different resource than for a normal fetch().

If a different response may result from setting this header, the server must include a {{HTTPHeader("Vary", "Vary: Service-Worker-Navigation-Preload")}} header in responses to ensure that different responses are cached.

For more information see {{domxref("NavigationPreloadManager.setHeaderValue()")}} (and {{domxref("NavigationPreloadManager")}}).

<table class="properties"> <tbody> <tr> <th scope="row">Header type</th> <td>{{Glossary("Request header")}}</td> </tr> <tr> <th scope="row">{{Glossary("Forbidden request header")}}</th> <td>No</td> </tr> </tbody> </table>

Syntax

http
Service-Worker-Navigation-Preload: <value>

Directives

  • <value>
    • : An arbitrary value that indicates what data should be sent in the response to the preload request. This defaults to true. It maybe set to any other string value in the service worker, using {{domxref("NavigationPreloadManager.setHeaderValue()")}}.

Examples

Service worker navigation preloading headers

The following request header is sent by default in navigation preload requests:

http
Service-Worker-Navigation-Preload: true

The service worker can set a different header value using {{domxref("NavigationPreloadManager.setHeaderValue()")}}. For example, in order to request that a fragment of the requested resource be returned in JSON format, the value could be set with the string json_fragment1.

http
Service-Worker-Navigation-Preload: json_fragment1

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also