此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。
Save-Data
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Save-Data 请求头字段是一个布尔值,在请求中,表示客户端对减少数据使用量的偏好。这可能是传输成本高,连接速度慢等原因。
值为 on 时,明确表示用户选择使用客户端简化数据使用模式,并且当与源进行通信时允许他们提供替代内容以减少下载的数据,例如较小的图像和视频资源,不同的标记和样式,禁用轮询和自动更新等。
备注:禁用 HTTP/2 服务器端推送 (RFC 7540, section 8.2: Server Push) 也可以用于减少数据下载。
In this article
语法
Save-Data: <sd-token>
指令
- <
sd-token> 一个数值,表示客户端是否想要选择简化数据使用模式。on 表示是,而 off(默认值)表示不。
示例
请求头Vary 确保正确缓存内容(例如,当 Save-Data 标头不再存在时,确保不从缓存向用户提供较低质量的图像 [例如在从蜂窝网络切换到 Wi-Fi 后])
携带Save-Data: on 请求头
请求示例:
GET /image.jpg HTTP/1.0Host: example.comSave-Data: on
响应示例:
HTTP/1.0 200 OKContent-Length: 102832Vary: Accept-Encoding, Save-DataCache-Control: public, max-age=31536000Content-Type: image/jpeg[...]
不携带Save-Data 请求头
请求示例:
GET /image.jpg HTTP/1.0Host: example.com
响应示例:
HTTP/1.0 200 OKContent-Length: 481770Vary: Accept-Encoding, Save-DataCache-Control: public, max-age=31536000Content-Type: image/jpeg[...]
规范
| Specification |
|---|
| Save Data API> # save-data-request-header-field> |
浏览器兼容性
参见
- Help Your Users
Save-Data- CSS Tricks - Delivering Fast and Light Applications with Save-Data - Google Developers
- Network Information API - WICG
- Header to indicate that the content served varies by
Save-Data:Vary