Client hints: What they are? How do they work? Why do we need them?

Thank you to Rowan Merewood for his patient explanation and review of this post. Client Hints are a content negotiation tool and can help with making responsive images easier to work with and give you other tools to help create a better user experience. They are a set of HTTP request headers allowing clients to indicate a list of device and browser preferences. Using client hints isn’t automatic: servers must tell clients what hints they want clients to send using the Accept-CH (accept client hints) header: Accept-CH: Width, Viewport-Width, Downlink or an equivalent HTML meta element with the http-equiv attribute.

Inserting meta tags in the head of a page

When researching client hints, I came across an interesting use case for dynamically inserting meta tags on a Handlebars template based on the route I’m accessing. The different pages of the experiment use different sets of client hints so each needs to request the different hints from the server, an Express application in this case. I wasn’t able to do it within Express or Handlebars so I had to hack my way through getting it done with Javascript. We also use local storage to set up a variable when we successfully add the meta tag. If the variable exists then

Working with Feature Policies in client-side Javascript

Note: The Feature-Policy header has been renamed to Permissions-Policy and browsers will soon start implementing the change.   The document.featurePolicy Javascript object will also change to document.permissionsPolicy. The Feature Policies Javascript API allows our client-side code to query for what features are available and what is restricted by Feature Policies. The Javascript API doesn’t replace the Feature-Policy header or the allow attribute of an iframe. You still need to set the header before this will work, or it will work with the default values. The downside is that the current version of feature/permissions policy doesn’t support setting the policies in

Testing front end with Mocha and Playwright

I’ve told myself for a while that I would learn how to write and use tests for front end code. Most of the code and tutorials I’ve seen are written for backend code. But using tools like Playwright together with Mocha and the Chai assertion library we can build very robust testing for front end code that works in multiple browsers. Background: Playwright Playwright is Microsoft’s browser testing and automation library. It allows you to control a browser: Chrome, Firefox, or Safari (WebKit) and perform operations as if you were working on the browser directly. Because we support multiple browsers

Aspect Ratio in CSS

Normally, only some elements have an aspect ratio, for example, images. For them, if only the width, or the height, is specified, the other is automatically computed using the intrinsic aspect ratio. In this example, the browser will calculate the height of the image using the width and the image’s intrinsic dimensions. <img src=”…” style=”width: 800px;”> The aspect-ratio property allows developers to explicitly set the aspect ratio of an element (not just those that already have an aspect ratio) and use it when one of the measurements is missing. The example below, taken From Una Kravetz codepen shows how this