Speculation-Rules 標頭
HTTP Speculation-Rules 響應標頭提供一個或多個 URL,指向包含推測規則 JSON 定義的文字資源。當響應是 HTML 文件時,這些規則將被新增到文件的推測規則集中。有關更多資訊,請參閱推測規則 API。
包含推測規則 JSON 的資原始檔可以有任何有效的名稱和副檔名,但它將以 destination 型別為 speculationrules 請求,並且必須以 application/speculationrules+json MIME 型別提供。
注意:此機制提供了一種替代方法,用於在內聯 <script type="speculationrules"> 元素中指定 JSON 定義。在開發人員無法直接修改文件本身的情況下,指定 HTTP 標頭會很有用。
語法
http
Speculation-Rules: <url-list>
指令
<url-list>-
一個逗號分隔的 URL 列表,指向包含推測規則 JSON 定義的文字資源。文字檔案中包含的 JSON 必須遵循與內聯
<script type="speculationrules">元素中包含的 JSON 相同的規則。有關語法參考,請參閱推測規則 JSON 表示。
示例
包含單個檔案的 Speculation-Rules 欄位
以下響應包含一個檔案引用
http
Speculation-Rules: "/rules/prefetch.json"
包含多個檔案的 Speculation-Rules 欄位
以下響應包含多個檔案引用,以逗號分隔列表形式
http
Speculation-Rules: "/rules/prefetch.json","/rules/prerender.json"
注意:URL 值必須包含在引號中。
規範
| 規範 |
|---|
| HTML # 推測規則標頭 |
瀏覽器相容性
載入中…