大网数据广告活动
Web 标准与前端开发

Sec-Speculation-Tags header

· 52CE 我爱测

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.

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).

<table class="properties"> <tbody> <tr> <th scope="row">Header type</th> <td>Request header</td> </tr> <tr> <th scope="row">Forbidden request header</th> <td>Yes (<code>Sec-</code> prefix)</td> </tr> </tbody> </table>

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

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。