diff options
Diffstat (limited to 'files/zh-cn/web/http/headers/save-data/index.html')
| -rw-r--r-- | files/zh-cn/web/http/headers/save-data/index.html | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/files/zh-cn/web/http/headers/save-data/index.html b/files/zh-cn/web/http/headers/save-data/index.html new file mode 100644 index 0000000000..ca37e92769 --- /dev/null +++ b/files/zh-cn/web/http/headers/save-data/index.html @@ -0,0 +1,104 @@ +--- +title: Save-Data +slug: Web/HTTP/Headers/Save-Data +tags: + - HTTP + - HTTP Header + - Reference + - Request header + - Save-Data + - header +translation_of: Web/HTTP/Headers/Save-Data +--- +<p>{{HTTPSidebar}}</p> + +<p>Save-Data请求头字段是一个布尔值,在请求中,表示客户端对减少数据使用量的偏好。 这可能是传输成本高,连接速度慢等原因。</p> + +<p>值为on时,明确表示用户选择使用客户端简化数据使用模式,并且当与源进行通信时允许他们提供替代内容以减少下载的数据,例如较小的图像和视频资源,不同的标记和样式,禁用轮询和自动更新等。</p> + +<div class="blockIndicator note"> +<p><strong>提示</strong>: 禁用 HTTP/2 服务器端推送 ({{RFC("7540", "Server Push", "8.2")}})也可以用于减少数据下载。</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">Save-Data: <sd-token></pre> + +<h2 id="指令">指令</h2> + +<dl> + <dt><<code>sd-token</code>></dt> + <dd>一个数值,表示客户端是否想要选择简化数据使用模式。 on表示是,而off(默认值)表示不。</dd> +</dl> + +<h2 id="示例">示例</h2> + +<p>请求头{{HTTPHeader("Vary")}} 确保正确缓存内容(例如,当Save-Data标头不再存在时,确保不从缓存向用户提供较低质量的图像[例如在从蜂窝网络切换到Wi-Fi后])</p> + +<h3 id="携带_Save-Data_on_请求头">携带 <code>Save-Data: on</code> 请求头</h3> + +<p>请求示例:</p> + +<pre>GET /image.jpg HTTP/1.0 +Host: example.com +Save-Data: on</pre> + +<p>响应示例:</p> + +<pre>HTTP/1.0 200 OK +Content-Length: 102832 +Vary: Accept-Encoding, Save-Data +Cache-Control: public, max-age=31536000 +Content-Type: image/jpeg + +[...] +</pre> + +<h3 id="不携带_Save-Data请求头">不携带 <code>Save-Data请求头</code></h3> + +<p>请求示例:</p> + +<pre>GET /image.jpg HTTP/1.0 +Host: example.com +</pre> + +<p>响应示例:</p> + +<pre>HTTP/1.0 200 OK +Content-Length: 481770 +Vary: Accept-Encoding, Save-Data +Cache-Control: public, max-age=31536000 +Content-Type: image/jpeg + +[...] +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Title</th> + </tr> + <tr> + <td><a href="https://tools.ietf.org/html/draft-grigorik-http-client-hints-03#section-7">draft-grigorik-http-client-hints-03, section 7: Save-Data</a></td> + <td>HTTP Client Hints</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("http.headers.Save-Data")}}</p> + +<h2 id="参见">参见</h2> + +<ul> + <li><a href="https://css-tricks.com/help-users-save-data/">Help Your Users `Save-Data` - CSS Tricks</a></li> + <li><a href="https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/save-data/">Delivering Fast and Light Applications with Save-Data - Google Developers</a></li> + <li><a href="https://wicg.github.io/netinfo/#save-data-request-header-field">Network Information API - WICG</a></li> + <li>Header to indicate that the content served varies by <code>Save-Data</code>: {{HTTPHeader("Vary")}}</li> +</ul> |
