function run() {
    var t = this
      , e = performance.timing
      , n = {}
      , r = function() {
        n["DNS解析时间"] = e.domainLookupEnd - e.domainLookupStart,
        n["TCP完成握手时间"] = e.connectEnd - e.connectStart,
        n["重定向时间"] = e.redirectEnd - e.redirectStart,
        n["html的ttfb耗时"] = e.responseStart - e.requestStart,
        n["HTTP请求响应完成时间"] = e.responseEnd - e.requestStart,
        n["DOM开始加载前所花费时间"] = e.responseEnd - e.navigationStart,
        n["DOM加载完成时间"] = e.domComplete - e.domLoading,
        n["DOM结构解析完成时间"] = e.domInteractive - e.domLoading,
        n["脚本加载时间"] = e.domContentLoadedEventEnd - e.domContentLoadedEventStart,
        n["onload事件时间"] = e.loadEventEnd - e.loadEventStart,
        n["页面完全加载时间"] = n["重定向时间"] + n["DNS解析时间"] + n["TCP完成握手时间"] + n["HTTP请求响应完成时间"] + n["DOM结构解析完成时间"] + n["DOM加载完成时间"],
        Object.keys(n).forEach((function(t) {
            console.log(t + ":" + n[t] + "ms")
        }
        ))
    };
    return r()
};
window.onload = function () {
    run()
}

博客地址:


老程
1 声望0 粉丝