Skip to content Skip to sidebar Skip to footer

How To Detect The Browser Support Http2 Or Not In Browser Environment By Javascript?

I want to determine use combo or not by the environment support http2 or not. But, I cannot find the method to check if a browser supports http2 or not in browser. Thank you in adv

Solution 1:

Navigation Timing 2 API provides this information:

performance.getEntriesByType('navigation')[0].nextHopProtocol

The above should return 'h2' on a page that got fetched using HTTP 2

A note on limited compatibility of nextHopProtocol:

Navigation Timing Level 2 API is currently in working draft status so support for the nextHopProtocol (which is being introduced with Level 2 API) will be limited (unsure of exact browsers supporting it since caniuse currently doesn't include Navigation Timing Level 2 API).

Solution 2:

According to HTTP/2 Frequently Asked QuestionsHTTP/2 and caniuse is supported at IE11, Edge14+, Firefox 52+, Chrome 49+, Safari 10.1+, Opera 45+, iOS Safari 9.3+, Android Browser 56, and Chrome for Android 59.

Can I use HTTP/2 now?

In browsers, HTTP/2 is supported by the most current releases of Edge, Safari, Firefox and Chrome. Other browsers based upon Blink will also support HTTP/2 (e.g., Opera and Yandex Browser). See the caniuse for more details.

Solution 3:

The easiest solution could be to find the User Browser version and user agent. Sample javascript code to find User Agent :

functionmyFunction() {
var x = "User-agent header sent: " + navigator.userAgent;
document.getElementById("demo").innerHTML = x;

}

We can make a Map with browser name and version and after splitting user agent we can know if the Browser version support or not.

With the server side language like Java, it's easy to get Request agent which can tell HTTP version, but with Javascript without Ajax, it's bit more code needs to write.

To find a number of Browser and which version of browser follows HTTP2 please refer to :

https://www.smashingmagazine.com/wp-content/uploads/2016/01/01-caniuse-spdy-opt.png

Solution 4:

I could not find another way. I think there is only way to check the browser and operating system by looking at the following items. https://en.wikipedia.org/wiki/HTTP/2http://caniuse.com/#search=http2

Post a Comment for "How To Detect The Browser Support Http2 Or Not In Browser Environment By Javascript?"