Is it possible to determine the HTTP protocol version using JavaScript? I need to detect if the user is using HTTP/2 protocol (and congratulate him if this was the case).
In Google Chrome and Brave, you can easily use the Developer tools (F12 or Command + Option + I ). Open the Network tab, find the request, click the Header tab, scroll down to "Response Headers", and click view source . It should show the HTTP version in the first line.
HTTP has four versions — HTTP/0.9, HTTP/1.0, HTTP/1.1, and HTTP/2.0. Today the version in common use is HTTP/1.1 and the future will be HTTP/2.0.
HTTP is a protocol for fetching resources such as HTML documents. It is the foundation of any data exchange on the Web and it is a client-server protocol, which means requests are initiated by the recipient, usually the Web browser.
Google Chrome offers a quick and easy way to check if HTTP/2 is supported on your SSL-enabled site. First, visit your site in Chrome over HTTPS. There you'll see your site listed with protocol h2, confirming your site works over HTTP/2.
console.log(performance.getEntries()[0].nextHopProtocol)
See also: https://caniuse.com/mdn-api_performanceresourcetiming_nexthopprotocol
Works in
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With