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

浏览器兼容性

另见