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

Speculation-Rules header

· 52CE 我爱测

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 A

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 will be requested with a destination type of speculationrules, and must be served with an application/speculationrules+json MIME type.

[!NOTE] This mechanism provides an alternative to specifying the JSON definition inside an inline <script type="speculationrules"> element. Specifying an HTTP header is useful in cases where developers are not able to directly modify the document itself.

<table class="properties"> <tbody> <tr> <th scope="row">Header type</th> <td>Response header</td> </tr> </tbody> </table>

Syntax

Speculation-Rules: <url-list>

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.

Examples

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 reference as a comma-separated list:

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

[!NOTE] The URL values must be contained in quotes.

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

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

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