Haproxy Early Hints

2019-02-12

One of the new features added to HAProxy 1.9 is Early Hints.

Sent as an early HTTP-103 header, Early Hints (rfc8297), might be a replacement for HTTP/2’s Server Push. The main difference between Early Hints and Server Push, is that Server Push actually sends data you might not need. HTTP-103 only sends a header, leaving the choice to the browser to actually start the transfer.

Enabling Early Hints

To enable early hints, add something like the following to your backend config:

http-request early-hint Link "<URL to CSS>; rel=preload; as=style"
http-request early-hint Link "<URL to JS>; rel=preload; as=script"

Where you can replace the URL with either a path relative to the root of your site or with a link to the file hosted in a CDN you might be using.

Caveats

Early Hints is definitely early tech. Expect unexpected behaviour. I had to make sure the Early Hints were only sent when using a negotiated HTTP/2 connection on my setup, due to some tools closing the connection after receiving HTTP headers they did not understand. In my case, these were Uptime Robot, and Google’s PageSpeed Insights. To only send Early Hints over HTTP/2, I added a condition:

http-request early-hint Link "</assets/main.js>; rel=preload; as=script" if { ssl_fc_alpn -i h2 }
http-request early-hint Link "</assets/style.css>; rel=preload; as=style" if { ssl_fc_alpn -i h2 }
http-request early-hint Link "</assets/62da0ac51db1e4a3a4d57b9154a344fc.woff>; rel=preload; as=font" if { ssl_fc_alpn -i h2 }
http-request early-hint Link "</assets/2bf08001f42c34e30e1de9d2eb81aead.woff>; rel=preload; as=font" if { ssl_fc_alpn -i h2 }

There might still be other unexpected behaviours, so keep an eye out when implementing Early Hints.

haproxy
Creative Commons License

Haproxy Cloud Native Logging