加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

window.performance javascript的解释

发布时间:2020-12-13 20:23:03 所属栏目:Windows 来源:网络整理
导读:我正在检测连接速度,所以我计划与 window.performance对象进行持续时间计算. 我很少与window.performance.timing对象混淆是基于整个页面加载生成的,或者基于最后的请求和响应. 例如: 我有5个服务器调用网页加载,performance.timing对象是基于所有5个服务器
我正在检测连接速度,所以我计划与 window.performance对象进行持续时间计算.

我很少与window.performance.timing对象混淆是基于整个页面加载生成的,或者基于最后的请求和响应.

例如:

我有5个服务器调用网页加载,performance.timing对象是基于所有5个服务器调用或基于第5个服务器调用(最后一次调用)生成的.

样品连接速度计算参考

var bitsLoaded = 100000; //bits total size of all files (5 server call).
 var duration = performance.timing.responseEnd - performance.timing.navigationStart;
 var speedBps = Math.round(bitsLoaded / duration);
 var speedKbps = (speedBps / 1024).toFixed(2);
 var speedMbps = (speedKbps / 1024).toFixed(2);

任何不清楚准备解释

任何关于window.performance的想法

不知道这个图表是否能让你更好地了解performance.timing.

对于你的问题:

I am having 5 server call for web page load,performance.timing object
is generated based on all the 5 server calls or based on the 5th
server call(last call).

答案是:performance.timing是基于所有请求和响应生成的(但不包括ajax).

对于您提供的示例连接速度计算脚本,我猜下面一个更好.

var duration = performance.timing.responseEnd - performance.timing.responseStart;

原因是:从navigationStart到responseEnd的持续时间包括不将任何数据从服务器传输到客户端的DNS定时.

有关定时的定义,请参考https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读