🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

Speculation Rules

HTTP Header

The HTTP Speculation-Rules response header provides one or more URLs pointing to text resources containing speculation rule JSON definitions. When the response is an HTML document, these rules will be added to the document’s speculation rule set. See the Speculation Rules API for more information.

The resource file containing the speculation rules JSON can have any valid name and extension, but it must be served with an application/speculationrules+json MIME type.

Header typeResponse header
Forbidden request headerNo

 

Syntax

Speculation-Rules: <url-list>

Speculation rules allow developers to control how browsers speculate on URLs, offering enhanced privacy and security controls.

Directives

<url-list>

A comma-separated list of URLs pointing to text resources containing speculation rule JSON definitions. The JSON contained in the text files must follow the same rules as that contained inside inline <script type="speculationrules"> elements. See Speculation rules JSON representation for the syntax reference.

Example

Speculation-Rules field with a single file

The following response contains one file reference:

Speculation-Rules: "/rules/prefetch.json"

Speculation-Rules field with multiple files

The following response contains multiple file references as a comma-separated list:

Speculation-Rules: "/rules/prefetch.json","/rules/prerender.json"

How to Modify Header using Requestly

Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the Speculation Rules header. This is particularly helpful for developers who want to control how browsers prefetch or prerender resources, helping improve performance or debug resource loading behavior. Steps to Modify the Speculation Rules Header:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. Add a new header modification:
    • Under “Action”, select “Add” or “Override”.
    • In the “Header Name” field, enter Speculation Rules.
    • In the “Header Value” field, enter your desired value (e.g., exclude=”#xyz”).
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-site.com/*).
  5. Save the rule.

Once configured, Requestly will modify the Speculation Rules header in all matching requests, letting you test how your site handles browser speculation behaviors such as prefetching or prerendering.