最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

browser - Detect connection protocol (HTTP2, spdy) from javascript - Stack Overflow

programmeradmin5浏览0评论

Is it possible to get the protocol that the browser used to get the active page?
Something like:

performance.navigation.protocol // e.g. "HTTP/2" or "SPDY/3.1" or "HTTP/1.1"

I know that it's possible to detect the protocol server side and then pass the info, but I'm looking for a JS solution.

(a similar question contains a broken link and no answer)

Is it possible to get the protocol that the browser used to get the active page?
Something like:

performance.navigation.protocol // e.g. "HTTP/2" or "SPDY/3.1" or "HTTP/1.1"

I know that it's possible to detect the protocol server side and then pass the info, but I'm looking for a JS solution.

(a similar question contains a broken link and no answer)

Share Improve this question edited May 23, 2017 at 11:46 CommunityBot 11 silver badge asked Mar 16, 2016 at 16:15 RazorRazor 29.7k8 gold badges56 silver badges77 bronze badges 3
  • can you make a HEAD request to location.hrefwith ajax? edit: nevermind, i don't see a response prop that would indicate it anyway... – dandavis Commented Mar 16, 2016 at 16:24
  • What do you need this for? – Bergi Commented Mar 23, 2016 at 15:01
  • 1 performance.getEntries()[0].nextHopProtocol works in Chrome – everconfusedGuy Commented Sep 8, 2017 at 11:31
Add a ment  | 

1 Answer 1

Reset to default 11

It is being standardised as performance.timing.nextHopProtocol, but chrome has a non-standard implementation already under window.chrome.loadTimes().connectionInfo:

if ( window.performance && performance.timing.nextHopProtocol ) {
    console.log('Protocol:' + performance.timing.nextHopProtocol);
} else if (window.performance && window.performance.getEntries) {
    console.log(performance.getEntries()[0].nextHopProtocol);
} else if ( window.chrome && window.chrome.loadTimes ) {
    console.log('Protocol:' + window.chrome.loadTimes().connectionInfo);
} else {
    console.log("Browser does not expose connection protocol");
}
发布评论

评论列表(0)

  1. 暂无评论