Accept-CH HTTP header is an integral part of the Client Hints infrastructure, which allows servers to opt-in to specific client-provided information about the client’s environment. This information assists servers in optimizing resource delivery and adjusting to the specific requirements or constraints of the client’s environment.
The Purpose of Accept-CH
This response header field is used by a server to declare which Client Hints it is interested in receiving in future requests, both in the current network session and in subsequent sessions. These hints can be utilized to customize responses based on device or network conditions, leading to better performance and a superior user experience.
Accept-CH header uses the following syntax:
<client-hint-token> represents one or more comma-separated tokens specifying the Client Hints that the server wants to receive. Each token corresponds to a specific type of client information, such as device memory, viewport width, or network connection type.
Here are a few examples of possible values for
DPR: Device pixel ratio
Viewport-Width: Width of the client’s viewport in CSS pixels
Width: Width of the requested resource in CSS pixels
Save-Data: The client’s preference for reduced data usage
How it Works: Request and Response
Let’s illustrate the use of the
Accept-CH header with a practical scenario:
When a client first requests a resource, the server might respond with an
Accept-CH header like this:
HTTP/1.1 200 OK Accept-CH: DPR, Width, Viewport-Width
In this response, the server is expressing interest in the client’s device pixel ratio (
DPR), the width of the requested resource (
Width), and the width of the client’s viewport (
Upon receiving this response, the client can choose to include these Client Hints in subsequent requests to the server. Here’s an example of what the next request from the client might look like:
GET /image.jpg HTTP/1.1 Host: example.com DPR: 2.0 Width: 1920 Viewport-Width: 980
In this request, the client is sending the device pixel ratio, the width of the requested resource, and the width of its viewport. The server can use this information to better tailor the response to the client’s device and viewing conditions.
Accept-CH header is not universally supported across all browsers and servers. For instance, Safari does not (yet) support Client Hints. Therefore, while using
Accept-CH and related headers, it is important to design your services to degrade gracefully for clients that do not support or respect these hints.
Accept-CH HTTP header is a powerful tool for enabling servers to customize their responses based on various aspects of the client’s environment, thus optimizing resource delivery. Although support for Client Hints is not universal, they can provide significant performance benefits when used properly. Always keep in mind both the server’s requirements and the client’s capabilities when implementing
Accept-CH in your services.