Firefox Tomorrow

http header

Sec-Speculation-Tags header

View on MDN ↗

Limited availability

The HTTP Sec-Speculation-Tags request header contains one or more tag values from the speculation rules that resulted in the speculation. This allows a server to identify which rule(s) caused a speculation and potentially block them.

For example, a CDN may automatically insert speculation rules, but block speculations for resources not cached in the CDN to avoid unintended consequences. The Sec-Speculation-Tags header allows the CDN to differentiate between the rules it has inserted (which should be blocked in this case) and speculation rules added by the site owner (which should not be blocked).

Header type [Request header](https://developer.mozilla.org/en-US/docs/Glossary/Request%20header)
[Forbidden request header](https://developer.mozilla.org/en-US/docs/Glossary/Forbidden%20request%20header) Yes (Sec- prefix)

Syntax

Sec-Speculation-Tags: <tag-list>

Directives

Examples

Speculation from a rule with no explicit tag

<script type="speculationrules">
  {
    "prefetch": [
      {
        "urls": ["next.html", "next2.html"]
      }
    ]
  }
</script>

If a speculation happens due to a speculation rule with no tag, then null is sent in the Sec-Speculation-Tags header.

Sec-Speculation-Tags: null

Speculation from a rule with a tag

<script type="speculationrules">
  {
    "prefetch": [
      {
        "tag": "my-rule",
        "urls": ["next.html", "next2.html"]
      }
    ]
  }
</script>

If a speculation happens due to a speculation rule with a tag, the tag name is sent in the Sec-Speculation-Tags header.

Sec-Speculation-Tags: "my-rule"

Speculation from a rule with multiple tags

The tag can be set at multiple levels:

<script type="speculationrules">
  {
    "tag": "my-ruleset",
    "prefetch": [
      {
        "tag": "my-rule",
        "urls": ["next.html", "next2.html"]
      }
    ]
  }
</script>

All matching tags are sent in the Sec-Speculation-Tags header, so in this case, both "my-ruleset" and "my-rule" would be sent:

Sec-Speculation-Tags: "my-ruleset", "my-rule"

Speculation from multiple rules

<script type="speculationrules">
  {
    "prefetch": [
      {
        "tag": "my-rule",
        "urls": ["next.html", "next2.html"],
        "eagerness": "moderate"
      }
    ]
  }
</script>
<script type="speculationrules">
  {
    "prefetch": [
      {
        "tag": "cdn-rule",
        "urls": ["next.html", "next.html"],
        "eagerness": "conservative"
      }
    ]
  }
</script>

In this example, if the speculation is initiated by the user hovering over the link for 200 milliseconds ("eagerness": "moderate"), then only the my-rule tag will be sent in the header:

Sec-Speculation-Tags: "my-rule"

However, if the link is clicked immediately, without waiting for the 200 millisecond hover, then both rules would have triggered a speculation, therefore both tags will be included in the header:

Sec-Speculation-Tags: "my-rule", "cdn-rule"

Speculation from multiple rules with and without tags

<script type="speculationrules">
  {
    "prefetch": [
      {
        "urls": ["next.html", "next2.html"],
        "eagerness": "moderate"
      }
    ]
  }
</script>
<script type="speculationrules">
  {
    "prefetch": [
      {
        "tag": "cdn-rule",
        "urls": ["next.html", "next.html"],
        "eagerness": "conservative"
      }
    ]
  }
</script>

Similar to the previous example, if the link is clicked immediately without waiting for the 200 millisecond hover, both rules would have triggered a speculation, therefore both tags will be included in the header. However, because the first rule does not include a tag field, it is represented in the header with a null value:

Sec-Speculation-Tags: null, "cdn-rule"

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also