blob: 36e8fa1dc7538339928acdca24ab387076379353 [file] [log] [blame] [view]
Tsuyoshi Horo61d47db42023-08-03 23:02:251# Compression Dictionary Transport
2
3- Contact: <compression-dictionary-transport-experiment@chromium.org>
4- Feedback: <https://github.com/WICG/compression-dictionary-transport/issues>
5- Chrome status: <https://chromestatus.com/feature/5124977788977152>
6
7## Introduction
8
9This document provides an overview of the current implementation status of the
10[**Compression Dictionary Transport**][explainer] feature in Chrome and
11instructions on how to enable it.
12
13Starting from version 117, Chrome experimentally supports Compression Dictionary
14Transport feature. This feature adds support for using designated previous
Tsuyoshi Horo27c43a3f2023-08-22 07:36:1415responses, as an external dictionary for Brotli- or Zstandard-compressed HTTP
16responses.
Tsuyoshi Horo61d47db42023-08-03 23:02:2517
18## Activation
19
20This API can be enabled by chrome://flags or via [Origin Trial][ot-blog].
21
22### chrome://flags
23
24If you want to try Compression Dictionary Transport feature, you have to enable
25both [chrome://flags/#enable-compression-dictionary-transport][flag] and
26[chrome://flags/#enable-compression-dictionary-transport-backend][backend-flag].
27The details about each flag are described [here][shared_dictionary_readme].
28
29### Origin Trial
30
31Origin Trial token can be obtained from [the Origin Trial console][ot-console].
32You can enable this feature by setting `Origin-Trials` HTTP response header in
33the page's HTML,
34
35```http
36Origin-Trial: YOUR_ORIGIN_TRIAL_TOKEN
37```
38
39or adding a meta tag in the &lt;header&gt; element.
40
41```html
42<meta http-equiv="origin-trial" content="YOUR_ORIGIN_TRIAL_TOKEN">
43```
44
45### Third-Party Origin Trial
46
47This feature supports third-party Origin Trial. If you are serving third-party
48scripts, you can enable this feature by adding a meta tag.
49
50```javascript
51(() => {
52 const meta = document.createElement('meta');
53 meta.httpEquiv = 'origin-trial';
54 meta.content = 'YOUR_THIRD_PARTY_ORIGIN_TRIAL_TOKEN';
55 document.head.appendChild(meta);
56})()
57```
58
59Currently third-party Origin Trial doesn't support `Origin-Trial` HTTP
60response header. See [this doc][third-party-ot-dd] for more details.
61
62### Origin Trial and the backend feature
63
64The origin trial token works only when the backend of this feature is enabled.
65Currently, the backend is gradually being rolled out. So the backend may not be
66enabled in your Chrome yet. If you want to try this feature using an Origin
67Trial token, please enable the backend at
68[chrome://flags/#enable-compression-dictionary-transport-backend][backend-flag].
69
70#### Why the backend is not enabled for all Chrome yet?
71
72When the backend is enabled, Chrome will check the dictionary database while
73fetching resources. This may negatively affect Chrome's loading performance.
74Therefore, we are conducting experiments to ensure that this does not cause
75regressions before rolling it out to all users.
76
Alison Gale59c007a2024-04-20 03:05:4077TODO(crbug.com/40255884): When we enable the backend for all Chrome, remove this
Tsuyoshi Horo61d47db42023-08-03 23:02:2578section.
79
80## Feature detection
81
82If you want to check whether the Compression Dictionary Transport feature is
83enabled or not, you can try the following code:
84
85```javascript
Tsuyoshi Horo6ca3287f2024-05-21 14:43:5586document.createElement('link').relList.supports('compression-dictionary')
Tsuyoshi Horo61d47db42023-08-03 23:02:2587```
88
89If the code above returns true, the Compression Dictionary Transport feature is
90enabled.
91
Tsuyoshi Horo6ca3287f2024-05-21 14:43:5592Note: Until M126, `dictionary` was used instead of `compression-dictionary`.
93
Tsuyoshi Horo61d47db42023-08-03 23:02:2594## Registering dictionaries
95
96When Chrome receives a HTTP response with `use-as-dictionary: <options>` header,
97and if the the response type is not opaque, Chrome registers the response as a
98dictionary.
99
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53100Chrome supports following options (see [the explainer][explainer] and [the
101spec draft][httpbis-draft] for more details):
Tsuyoshi Horo61d47db42023-08-03 23:02:25102
103- **match**
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53104 - The URL Pattern [URLPattern] to use for request matching.
105- **match-dest**
106 - List of request destinations for the dictionary to match.
107- **id**
108 - The dictionary ID.
109 - This ID is sent to the server in a "Dictionary-ID" request header when the
110 dictionary is available.
Tsuyoshi Horo49d12a1e2023-08-10 21:42:03111- **type**
112 - Dictionary format.
113 - This field is optional and defaults to `raw`.
114 - Currently Chrome only supports `raw`. So if this field is set but it is not
115 `raw`, Chrome doesn't register the response as a dictionary. This logic of
116 checking **type** was [introduced at M118][type-option-cl].
Tsuyoshi Horo61d47db42023-08-03 23:02:25117
118Note: These options fields are expected to change when we officially launch this
119feature, depending on the outcome of [the spec discussion][httpbis-draft].
120
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53121## Dictionary lifetime
122
123The lifetime of registered dictionary is calculated from the response's
124[freshness](https://datatracker.ietf.org/doc/html/rfc9111#name-freshness).
125
126While running the Origin Trial experiment, the max expiration time is
127limited to 30 days. This limitation can be removed by enabling
128[chrome://flags/#enable-compression-dictionary-transport][flag].
129
Tsuyoshi Horo61d47db42023-08-03 23:02:25130## Fetching dedicated dictionaries
131
132Chrome fetches a dedicated dictionary when it detects
Tsuyoshi Horo6ca3287f2024-05-21 14:43:55133`<link rel="compression-dictionary" href="DICTIONARY_URL">` in the page, or
134`Link: <DICTIONARY_URL>; rel="compression-dictionary"` HTTP response header is
135set in the response of the page's HTML file.
136
137Note: Until M126, `dictionary` was used instead of `compression-dictionary`.
Tsuyoshi Horo61d47db42023-08-03 23:02:25138
139## Using dictionaries
140
141While fetching a HTTP request, Chrome match the request against the available
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53142dictionary `match` URL patterns.
Tsuyoshi Horo61d47db42023-08-03 23:02:25143
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53144If a dictionary is available for the request, Chrome will add `dcb` and `dcz`in
145the `Accept-Encoding` request header, as well as a
146`Available-Dictionary: <SHA-256>` header with the hash of the dictionary.
Tsuyoshi Horo61d47db42023-08-03 23:02:25147
148## Supported compression scheme
149
Tsuyoshi Horo27c43a3f2023-08-22 07:36:14150Chrome 117.0.5857.0 introduced support for Shared Brotli, and Chrome
151118.0.5952.0 adds support for Shared Zstandard.
152
153Shared Zstandard can be enabled/disabled from
154[chrome://flags/#enable-shared-zstd][shared-zstd-flag].
Tsuyoshi Horo61d47db42023-08-03 23:02:25155
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53156Until M126, `br-d` and `zstd-d` encoding was used. After M127, `dcb` and `dcz`
157encodings are used. See [this spec
158change](https://github.com/httpwg/http-extensions/pull/2784) for more details
159about this change of the encoding.
160
Tsuyoshi Horo47cfd6ea2023-11-28 11:10:35161## Supported HTTP protocol
162
163From Chrome 121, Chrome may not use stored shared dictionares when the
Tsuyoshi Horo42fb8d02024-04-11 01:47:55164connection is using HTTP/1 for non-localhost requests. From Chrome 125, Chrome
165may not use stored shared dictionares when the connection is using HTTP/2 for
166non-localhost requests.
167Also Chrome may not use shared dictionares when the HTTPS connection's
168certificate is not rooted by a well known root CA (eg: using a user installed
169root certificate). This is for an investigation for an issue that some network
170appliances are interfering with HTTPS traffic by inspecting encrypted responses
171but failing to properly decode the shared dictionary encoded content.
Tsuyoshi Horo47cfd6ea2023-11-28 11:10:35172
173If you want to use shared dictionaries with HTTP/1, please enable
Tsuyoshi Horo42fb8d02024-04-11 01:47:55174[chrome://flags/#enable-compression-dictionary-transport-allow-http1][allow-http1-flag].
175If you want to use shared dictionaries with HTTP/2, please enable
176[chrome://flags/#enable-compression-dictionary-transport-allow-http2][allow-http2-flag].
Tsuyoshi Horo2cce8d52023-12-04 15:07:05177Also if you want to use shared dictionaries over the HTTPS connection which
178certificate is not rooted by a well known root CA, please disable
179[chrome://flags/#enable-compression-dictionary-transport-require-known-root-cert][require-known-root-ca-flag].
Tsuyoshi Horo47cfd6ea2023-11-28 11:10:35180
Tsuyoshi Horo61d47db42023-08-03 23:02:25181## Debugging
182
183### Managing registered dictionaries
184
185Developers can manage the registered dictionaries in
186[chrome://net-internals/#sharedDictionary][net-internals-sd].
187
188### DevTools
189
190Developers can check the related HTTP request and response headers
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53191(`Use-As-Dictionary`, `Available-Dictionary`, `Accept-Encoding` and
Tsuyoshi Horo61d47db42023-08-03 23:02:25192`Content-Encoding`) using DevTools' Network tab.
193
194## Known issues
195
196- [crbug.com/1468156](crbug.com/1468156): `encodedBodySize` property and
197 `transferSize` property of `PerformanceResourceTiming` for shared dictionary
198 compressed response are wrong. Currently it returns as if the response is not
199 compressed.
200
Tsuyoshi Horo40d4e432024-02-08 12:42:22201## Changes in M123
Tsuyoshi Horo02878d32024-01-12 05:21:57202
Tsuyoshi Horo40d4e432024-02-08 12:42:22203The following changes have been made to Chrome since M123 to keep up with the
204changes in specifications.
Tsuyoshi Horo02878d32024-01-12 05:21:57205
Tsuyoshi Horo40d4e432024-02-08 12:42:22206- Changed Content-Encoding name "br-d" "zstd-d"
Tsuyoshi Horo02878d32024-01-12 05:21:57207- Changed match to use URLPattern
Tsuyoshi Horo02878d32024-01-12 05:21:57208- Added support for a server-provided dictionary id
Tsuyoshi Horo47afd652024-01-24 11:47:09209- Stop using "expires" value of "Use-As-Dictionary" header, and use the cache
210 expiration time calculated from the response's freshness instead.
Tsuyoshi Horo02878d32024-01-12 05:21:57211- Removed support for hash negotiation and force use of sha-256
Tsuyoshi Horo02878d32024-01-12 05:21:57212- Added the dictionary hash to the compressed response
Tsuyoshi Horo02878d32024-01-12 05:21:57213- Dictionary hashes changed to sf-binary
Tsuyoshi Horo1659f912024-01-24 06:30:03214- Use "Available-Dictionary" header instead of "Sec-Available-Dictionary"
Tsuyoshi Horod343478b2024-02-07 01:45:08215- Added support for match-dest option
Tsuyoshi Horo02878d32024-01-12 05:21:57216
Tsuyoshi Horo6ca3287f2024-05-21 14:43:55217## Changes in M127
218
219The following changes have been made to Chrome since M127 to keep up with the
220changes in specifications.
221
222- `compression-dictionary` rel attribute is used for HTML `link` element and
223 HTTP `Link:` header instead of `dictionary`.
Tsuyoshi Horod934bf32024-05-23 02:02:45224- Changed Content-Encoding to use "dcb" and "dcz".
225 See [this spec change](https://github.com/httpwg/http-extensions/pull/2784).
226
Tsuyoshi Horo61d47db42023-08-03 23:02:25227## Demo sites
228
229There are a few demo sites that you can use to test the feature:
230
231- Shopping site demo (dynamic resources flow)
232 <https://compression-dictionary-transport-shop-demo.glitch.me/>
233- Three JS demo (static resources flow)
234 <https://compression-dictionary-transport-threejs-demo.glitch.me/>
235
236[explainer]: https://github.com/WICG/compression-dictionary-transport
237[flag]: chrome://flags/#enable-compression-dictionary-transport
238[backend-flag]: chrome://flags/#enable-compression-dictionary-transport-backend
Tsuyoshi Horo27c43a3f2023-08-22 07:36:14239[shared-zstd-flag]: chrome://flags/#enable-shared-zstd
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53240[allow-http1-flag]: chrome://flags/#enable-compression-dictionary-transport-allow-http1
241[allow-http2-flag]: chrome://flags/#enable-compression-dictionary-transport-allow-http2
Tsuyoshi Horo2cce8d52023-12-04 15:07:05242[require-known-root-ca-flag]: chrome://flags/#enable-compression-dictionary-transport-require-known-root-cert
Tsuyoshi Horo61d47db42023-08-03 23:02:25243[shared_dictionary_readme]: ../../services/network/shared_dictionary/README.md#flags
244[ot-blog]: https://developer.chrome.com/blog/origin-trials/
245[ot-console]: https://developer.chrome.com/origintrials/#/trials/active
Tsuyoshi Horo61d47db42023-08-03 23:02:25246[third-party-ot-dd]: https://docs.google.com/document/d/1xALH9W7rWmX0FpjudhDeS2TNTEOXuPn4Tlc9VmuPdHA/edit#heading=h.bvw2lcb2dczg
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53247[httpbis-draft]: https://datatracker.ietf.org/doc/draft-ietf-httpbis-compression-dictionary/
Tsuyoshi Horo61d47db42023-08-03 23:02:25248[net-internals-sd]: chrome://net-internals/#sharedDictionary
Tsuyoshi Horo49d12a1e2023-08-10 21:42:03249[type-option-cl]: https://chromiumdash.appspot.com/commit/169031f4af2cbdc529f48160f1df20b4ca8b6cc1
Tsuyoshi Horoceee8dbd2024-05-25 00:39:53250[URLPattern]: https://urlpattern.spec.whatwg.org/