Chrome DEVTools的NETWORK面板 - pod4g/tool GitHub Wiki

参考资料:谷歌chrome开发文档

大小相关

Size:Size is the combined size of the response headers (usually a few hundred bytes) plus the response body, as delivered by the server;

Size = 响应头(大小通常为几百byte)+ 响应体;size是真正走网络的大小。

Content:Content is the size of the resource's decoded content

Content是资源在硬盘上的真实大小。

大多数情况下服务器会启用GZIP压缩,所以有size < content,对于文本,压缩率一般大于10倍。

但若是图片或font字体,那么GZIP压缩不起作用,此时有size = content + response header,所以有size > content,可以认为size - content等于response header

2016-07-19更新:

如果非图片和非font字体,如何计算response headers的大小呢?

可以看response headers中的 Content-Length ,这个是资源的真实走网络大小,单位是byte,

response headers = size - Content-Length

:100:


时间相关

Time:Time is total duration, from the start of the request to the receipt of the final byte in the response

Time是一个资源从开始发送请求到接受到该资源的最后一个byte时的总用时

Latency:Latency is the time to load the first byte in the response

Latency是一个资源从开始发送请求到接收到该资源的第一个byte时的总用时

所以,Latency < Time 永远成立,Time - Latency的差值就是资源下载的时间

2016-07-19更新:

TTFB (Time To First Byte),是最初的网络请求被发起到从服务器接收到第一个字节这段时间,它包含了 TCP连接时间,发送HTTP请求时间和获得响应消息第一个字节的时间。
- 上面是百度百科的解释
但是在chrome上,只包含刚开始发送request到接收到第一个byte的时间,发送request前面的预操作则不算在内

Timeline中有两条垂直线,一条蓝色的线是DOMContentLoaded事件触发的时间点,一条红色的线是load事件触发的时间点

含DNS Lookup 和 Initial connection:

含DNS Lookup 和 Initial connection

Queueing + Stalled + Proxy negotiation + DNS Lookup + Initial connection + Request sent + TTFB + Content Download = Explanation

Stalled + Proxy negotiation + DNS Lookup + Initial connection + Request sent + TTFB + Content Download = Time

因此有 Queueing + Time = Explannation

不含DNS Lookup 和 Initial connection:

不含DNS Lookup 和 Initial connection

Queueing + Stalled + Proxy negotiation + Request sent + TTFB + Content Download = Explanation

Stalled + Proxy negotiation + Request sent + TTFB + Content Download = Time

因此也有 Queueing + Time = Explannation

如果含SSL,那么ExplannationTime都不把SSL计算在内。当scheme是HTTPS时,会有SSL,这也是HTTPS慢的原因之一

以上的等式都为约等且不遵循四舍五入


/*
 测网速函数。所测速度与network显示的差别不大
*/
function testSpeed(url,fileSize){
    var startTime,endTime,duration,speedBps,speedKbps,speedMbps;
    var download = new Image();
    var size = fileSize * 8;
    download.onload = function(){
        endTime = +new Date();
        duration = (endTime - startTime)/1000;
        speedBps = (size / duration).toFixed(2);
        speedKbps = (speedBps / 1024).toFixed(2);
        speedMbps = (speedKbps / 1024).toFixed(2);
        console.log("duration(ms):"+(endTime - startTime));
        console.log("duration(s):"+duration.toFixed(2));
        console.log("speedBps:"+speedBps);
        console.log("speedKbps:"+speedKbps);
        console.log("speedMbps:"+speedMbps);

    }
    startTime = +new Date();
    download.src = url + "?n=" + Math.random();
 }
 testSpeed("http://t.diaox2.com/view/test/lyf/test_speed.jpeg",13129);
 // testSpeed("http://t.diaox2.com/view/test/lyf/test_speed2.png",2660306);