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 advance.
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).
According to HTTP/2 Frequently Asked Questions HTTP/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.
The easiest solution could be to find the User Browser version and user agent. Sample javascript code to find User Agent :
function myFunction() { 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
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/2
http://caniuse.com/#search=http2
chrome.loadTimes().connectionInfo. Also related if not dupe, but can't be marked as dupe because no answers : stackoverflow.com/questions/44842659/…<script src="??/a.js,/b.js"></script>, else this should be done in the format:<script src="/a.js" async defer></script><script src="/b.js" async defer></script>.<script>const script = document.createElement('script'); script.src = '/a.js'; document.head.appendChild(script);</script>.'/a.js'through HTTP/1.1, it actually serves the content of'/b.js'.