Client hints - MDN Web Docs Glossary: Definitions of Web-related terms 编辑

Client Hints are a set of HTTP request header fields for proactive content negotiation allowing clients to indicate a list of device and agent specific preferences.

Use of client hints isn't automatic: rather, servers must announce that they support client hints. Servers announce support for Client Hints using the Accept-CH (accept client hints) header or an equivalent HTML meta element with the http-equiv attribute.

Accept-CH: Width, Viewport-Width, Downlink

and / or

<meta http-equiv="Accept-CH" content="Width, Viewport-Width, Downlink">

When a client receives the Accept-CH header, if supported, it appends Client Hint headers that match the advertised field-values. For example, based on Accept-CH example above, the client could append Width, Viewport-Width, and Downlink headers to all subsequent requests. In the second example, the server gives the browser the hints by setting the Accept-CH meta tag.

Basically, with the Client Hints header, the developer or application can tell the browser to advertise information about itself to the server, such as the device pixel ratio, the viewport width, and the display width. The client can then give the server information about the client's environment, and the server can determine which resources to send based on that information.

Varying Client Hints

To convey to caches that different Client Hints may affect the response, the Vary HTTP header must be used.

Example varying response:

Vary: Accept, Width, Viewport-Width, Downlink

See Also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:124 次

字数:2449

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文