Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

http-client-hints

> 编程语言
Open source

Development of this specification has moved to the HTTPWG repository. For latest drafts and issue discussions, head to: - https://github.co…

400 stars0 likes2 views
WebsiteGitHub

About

Development of this specification has moved to the HTTPWG repository. For latest drafts and issue discussions, head to: - https://github.co…

Development of this specification has moved to the HTTPWG repository. For latest drafts and issue discussions, head to:

  • https://github.com/httpwg/http-extensions#client-hints
  • https://httpwg.github.io/http-extensions/client-hints.html

HTTP Client Hints Explainer

This specification defines a set of HTTP request header fields, colloquially known as Client Hints, that are intended to be used as input to proactive content negotiation; just as the Accept header allows clients to indicate what formats they prefer, Client Hints allow clients to indicate a list of device and agent specific preferences.

  • Available hints
  • Opt-in hint delivery
  • Use cases
    • Responsive Design + Server Side Components (RESS)
    • [`` element](#img-element)
      • Delivering DPR-aware images
      • Delivering DPR and resource width aware images
    • [`` element](#picture-element)
      • Device-pixel-ratio-based selection
      • Device-pixel-ratio and viewport-based selection
      • Resource selection
    • Maximum downlink speed
  • Hands-on example
  • Implementation status

Available hints

Current list includes DPR (device pixel ratio), Width (resource width), Viewport-Width (layout viewport width), and Downlink (maximum downlink speed) request headers, and Content-DPR response header that is used to confirm the DPR of selected image resources - see full definitions in latest spec.

Note: have a proposal for another hint? Open an issue, document your use case.

Opt-in hint delivery

To reduce request overhead the hints are sent based on opt-in basis: the server advertises supported hints, the user agent sends the appropriate hint request headers for subsequent requests - see Advertising Support for Client Hints.

Note that this means that the user agent will not send hints on the very first request. However, if the site provides correct opt-in information in the response, hints will be delivered by all subsequent requests. Also, the user agent may remember site opt-in across browsing sessions, enabling hint delivery of all subsequent requests.

Use cases

Responsive Design + Server Side Components (RESS)

The application may want to deliver alternate set of optimized resources based on advertised hints. For example, it may use the device pixel ratio (DPR), or the layout viewport width (Viewport-Width) to respond with optimized HTML markup, CSS, or script resources - see Responsive Design + Server Side Components (RESS).

Note: Applications that use this approach must also serve appropriate Vary and Cache-Control response headers to ensure correct delivery of optimized assets.

`` element

Delivering DPR-aware images

DPR hint automates device-pixel-ratio-based selection and enables delivery of optimal image variant without any changes in markup. For example, given the following HTML markup:

xml

The client and server can negotiate the appropriate resolution of img.jpg via HTTP negotiation:

http
GET /img.jpg HTTP/1.1
User-Agent: Awesome Browser
Accept: image/webp, image/jpg
DPR: 2.0
http
HTTP/1.1 200 OK
Server: Awesome Server
Content-Type: image/jpg
Content-Length: 124523
Vary: DPR
Content-DPR: 2.0

(image data)

In the above example, the user agent advertises its device pixel ratio via DPR request header on the image request. Given this information, the server is able to select and respond with the optimal resource variant for the client. For full details refer to the latest spec.

Note: when server side DPR-selection is used the server must confirm the DPR of the selected resource via Content-DPR response header to allow the user agent to compute the correct intrinsic size of the image.

Delivering DPR and resource width aware images

If the image resource width is known at request time, the user agent can communicate it to the server to enable selection of an optimized resource. For example, given the following HTML markup:

xml

The client and server can negotiate an optimized asset based on DPR and Width request hints:

http
GET /img.jpg HTTP/1.1
User-Agent: Awesome Browser
Accept: image/webp, image/jpg
DPR: 2.0
Width: 320
http
HTTP/1.1 200 OK
Server: Awesome Server
Content-Type: image/jpg
Content-Length: 124523
Vary: Width
Content-DPR: 2.0

(image data)

In the above example, the user agent advertises its device pixel ratio and image resource width via respective DPR and Width headers on the image request. Given this information, the server is able to select and respond with the optimal resource variant for the client:

  • The server can scale the asset to requested width, or return the closest available match to help reduce number of transfered bytes.
  • The server can factor in the device pixel ratio of the device in its selection algorithm.

Note that the width of the image may not be available at request time, in which case the user agent would omit the Width hint. Also, the exact logic as to which asset is selected is deferred to the server, which can optimize its selection based on available resources, cache hit rates, and other criteria.

`` element

Client Hints can be used alongside picture element to automate resolution switching, simplify art-direction, and automate delivery of variable-sized images.

Device-pixel-ratio-based selection

DPR header automates device-pixel-ratio-based selection by eliminating the need to write x descriptors for img and picture elements:

xml

  
  

  
  
  

  
  
  

Note that the second example with art direction-based selection illustrates that hints do not eliminate the need for the picture element. Rather, Client Hints is able to simplify and automate certain parts of the negotiation, allowing the developer to focus on art direction, which by definition requires developer/designer input.

Device-pixel-ratio and viewport-based selection

The combination of DPR and Width hints also simplifies delivery of variable sized images when viewport-based selection is used. The developer specifies the resource width of the image in vw units (which are relative to viewport width) via sizes attribute and the user agent handles the rest:

xml
  • Device pixel ratio is communicated via the DPR request header
  • The vw size is converted to physical px size based on client's layout viewport size and the resulting value is communicated via the Width request header
  • The server computes the optimal image variant based on communicated DPR and Width values and responds with the optimal image variant.

HTTP negotiation flow for the example above:

…

ReSRC.it servers automate the delivery of optimal image assets based on advertised DPR and Width hint values and append the correct caching header (Vary: DPR, Width), which allows the asset to be cached on the client and by any Vary-capable intermediaries.

Implementation status

  • Blink: shipped in M46.
    • Automating resource selection with Client Hints (Web Fundamentals).
    • Leaner Responsive Images With Client Hints (Smashing Magazine).
  • IE: Under Consideration
  • Mozilla: 935216 - Implement Client-Hints HTTP header

Feedback

Please feel free to open a new issue, or send a pull request!

Issues· 1 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言