Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the HTTP protocol version via JavaScript

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).

like image 325
Salman A Avatar asked Feb 27 '15 19:02

Salman A


People also ask

How do I know what version my HTTP is?

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.

What is HTTP version number?

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.

What is HTTP protocol in web api?

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.

How do I know if http2 is requested?

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.


1 Answers

console.log(performance.getEntries()[0].nextHopProtocol)

See also: https://caniuse.com/mdn-api_performanceresourcetiming_nexthopprotocol

Works in

  • Edge since 17
  • Firefox (Desktop and Mobile) since 45
  • Chrome (Desktop and Mobile) since 61
  • Safari Mac 14.1 (tested here, but not yet updated on MDN/caniuse)
like image 111
everconfusedGuy Avatar answered Sep 20 '22 14:09

everconfusedGuy