Use-As-Dictionary 頭部

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

HTTP Use-As-Dictionary 響應頭列出了壓縮字典傳輸字典在未來請求中可用於的匹配條件。

有關更多資訊,請參閱壓縮字典傳輸指南

語法

http
Use-As-Dictionary: match="<url-pattern>"
Use-As-Dictionary: match-dest=("<destination1>" "<destination2>", …)
Use-As-Dictionary: id="<string-identifier>"
Use-As-Dictionary: type="raw"

// Multiple, in any order
Content-Encoding: match="<url-pattern>", match-dest=("<destination1>")

指令

match

一個字串值,包含一個URL 模式:只有 URL 與此模式匹配的資源才能使用此資源作為字典。不允許使用正則表示式捕獲組,因此URLPattern.hasRegExpGroups必須為false

match-dest

一個以空格分隔的字串列表,每個字串用引號引起來,整個值括在括號中,提供了一個Fetch 請求目標列表,如果請求要使用此字典,則必須匹配這些目標。

id

一個字串值,為字典指定伺服器識別符號。當瀏覽器請求可以使用此字典的資源時,此 ID 值將新增到Dictionary-ID請求頭中。

type

一個字串值,描述所提供字典的檔案格式。目前只支援raw(預設值),因此這更多是為了未來相容性。

示例

路徑字首

http
Use-As-Dictionary: match="/product/*"

這表示字典只能用於以/product/開頭的 URL。

版本化目錄

http
Use-As-Dictionary: match="/app/*/main.js"

這使用萬用字元來匹配檔案的多個版本。

目標

http
Use-As-Dictionary: match="/product/*", match-dest=("document")

這使用match-dest來確保字典僅用於document請求,因此例如<script src="/product/js/app.js">資源請求將不匹配。

http
Use-As-Dictionary: match="/product/*", match-dest=("document" "frame")

這將允許字典匹配頂級文件和 iframe。

Id

http
Use-As-Dictionary: match="/product/*", id="dictionary-12345"

Use-As-Dictionary包含id指令時(如本例所示),id值將包含在可使用此字典的資源的Dictionary-ID請求頭中。資源請求還將包含由冒號包圍的字典的 SHA-256 雜湊值,位於Available-Dictionary頭中。

http
Accept-Encoding: gzip, br, zstd, dcb, dcz
Available-Dictionary: :pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4=:
Dictionary-ID: "dictionary-12345"

伺服器仍然必須檢查來自Available-Dictionary頭的雜湊值——Dictionary-ID是伺服器識別字典的附加資訊,但不能替代對Available-Dictionary頭的需求。

型別

http
Use-As-Dictionary: match="/product/*", type="raw"

目前,只支援raw(預設值),因此這更多是為了未來相容性。

規範

規範
壓縮字典傳輸
# name-use-as-dictionary

瀏覽器相容性

另見