Web App Performance

HTTP Client Hints

Maximiliano Firtman

Maximiliano Firtman

Independent Consultant
Web App Performance

Check out a free preview of the full Web App Performance course

The "HTTP Client Hints" Lesson is part of the full, Web App Performance course featured in this preview video. Here's what you'd learn in this lesson:

Max discusses how HTTP Client Hits allow the browser to expose device information to the server by using a meta tag in the HTML. This information helps the server decide which asset to return.


Transcript from the "HTTP Client Hints" Lesson

>> HTTP Client Hints. The idea is for external resources. We are talking about resource loading. What if the server can receive data about the client to make better decisions about the resource that it's going to send you? For example, images. What if the server knows the pixel density or the resolution of the current device?

So if you're asking me for an image, I know if you are on a laptop computer, if you're on a laptop with a retina screen, so with more resolution, if you're on an iPhone, if you're on an Android, based on that, without using the picture elements, so the server will make a decision.

And for that, we can expose data to the server with a spec known as HTTP Client Hints. It's a meta tag that you can define in the header of your HTML, actually more than a meta tag, it's an HTTP header that you can also express as a meta tag, that's better.

Accept-CH, CH, client hints. And in the content, you set a comma-separated list of properties that you want, okay? Give me a second. We can ask today for RTT, Round Trip Time. So that's the latency. We can send to the server the current estimated latency that we are having, so the server can decide what to return.

Downlink, that's an estimation of the bandwidth. So again, if the latency is 400 milliseconds, something's wrong with our connection. So the server can say, well, let's return something simpler, let's increase the experience for that user. Does it make sense? This is the effective connection type, ECT, effective connection type.

It will give you a string if you are in 2g, 3g, 4g, slow-2g, and that's all. So there is no 5g or Wi-Fi. In those cases, they will give you a 4g, the best one. Save-Data, that's a boolean value that will give you the hint that the user wants to save data.

What does it mean for you? It's your problem. So you can return images in low resolution if you wanna honor that settings. Where is the settings? I will show you what it is, but on an Android, on Chrome, for example, you have a settings Save-Data in the menu.

On iOS, you need to enable that in your current connection settings in the Wi-Fi or in your data connection plan that you have with your carrier, you can enable Save-Data. DPR, that's device pixel ratio. That's the resolution, the pixel density. Viewport width, that's the actual width in CSS pixels.

And device memory, how much memory the device has. So you can request the client, the browser, to send the data to every resource HTTP request. That's an HTTP client hint. Does that make sense? If you have a lot of work server-side to do something with the information, OK, with a hint.

But the idea is to increase the user experience. By the way, the memory is expressed in MiB, that we know that it's not men in black, okay, it's mebibytes. So now you will see that many times. By the way, so the idea that we have kilobytes and kibibytes, it's the only thing that I know that you will remember from today's course.

That's the only thing you will remember.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now