【问题标题】:Detect connection protocol (HTTP/2, spdy) from javascript从 javascript 检测连接协议(HTTP/2、spdy)
【发布时间】:2016-07-02 15:49:08
【问题描述】:

是否可以获得浏览器用于获取活动页面的协议?
比如:

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

我知道可以检测到协议服务器端然后传递信息,但我正在寻找 JS 解决方案。

similar question 包含断开的链接且没有答案)

【问题讨论】:

  • 你能用 ajax 向location.href发出 HEAD 请求吗?编辑:没关系,我没有看到任何表明它的响应道具......
  • 你需要这个做什么?
  • performance.getEntries()[0].nextHopProtocol 在 Chrome 中工作

标签: javascript browser


【解决方案1】:

它是 standardisedperformance.timing.nextHopProtocol,但 chrome 在 window.chrome.loadTimes().connectionInfo 下已经有一个 non-standard implementation

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");
}

【讨论】:

    猜你喜欢
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 2018-12-07
    • 2013-02-18
    • 1970-01-01
    • 2015-08-09
    • 2021-06-03
    相关资源
    最近更新 更多