Skip to content

Instantly share code, notes, and snippets.

@ajtatum
Created January 15, 2021 23:42
Show Gist options
  • Save ajtatum/f920fc392de2bdaeaf5184277b1fd5ca to your computer and use it in GitHub Desktop.
Save ajtatum/f920fc392de2bdaeaf5184277b1fd5ca to your computer and use it in GitHub Desktop.
ImageKit Client Hints
var imageCdnUrl = Configuration["CDN:Images:CdnUrl"];
app.Use(async (context, next) =>
{
context.Response.Headers.Add("Accept-CH", "viewport-width, width, dpr");
context.Response.Headers.Add("Feature-Policy", $"ch-viewport-width {imageCdnUrl};ch-width {imageCdnUrl};ch-dpr {imageCdnUrl};ch-device-memory {imageCdnUrl};ch-rtt {imageCdnUrl};ch-ect {imageCdnUrl};ch-downlink {imageCdnUrl}");
context.Response.Headers.Add("Permissions-Policy", $"ch-viewport-width {imageCdnUrl};ch-width {imageCdnUrl};ch-dpr {imageCdnUrl};ch-device-memory {imageCdnUrl};ch-rtt {imageCdnUrl};ch-ect {imageCdnUrl};ch-downlink {imageCdnUrl}");
await next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment