问题
I've checked on similar questions and found two options I can proceed with, however both have problematic issues.
if ( performance && performance.timing.nextHopProtocol ) {
console.log('Protocol:' + performance.timing.nextHopProtocol);
} else if ( window.chrome && window.chrome.loadTimes ) {
console.log('Protocol:' + window.chrome.loadTimes().connectionInfo);
} else {
console.log("Browser does not expose connection protocol");
}
The above code does return the protocol however, while using my chrome it supports http2 and is capable, but still returns http1.
On another solution is to compile a list of supported browsers and cross check the http_useragent, however the list should be checked in from time to time and also cross check the OS versions. since for example IE 11 on windows 10 works but for let's say lower version it wont.
来源:https://stackoverflow.com/questions/44842659/detect-browser-if-capable-enabled-for-http2-via-javascript-or-php