- DNS 解析耗时: domainLookupEnd - domainLookupStart
- TCP 连接耗时: connectEnd - connectStart
- SSL 安全连接耗时: connectEnd - secureConnectionStart
- 网络请求耗时 (TTFB): responseStart - requestStart
- 数据传输耗时: responseEnd - responseStart
- DOM 解析耗时: domInteractive - responseEnd
- 资源加载耗时: loadEventStart - domContentLoadedEventEnd
- First Byte时间: responseStart - domainLookupStart
- 白屏时间: responseEnd - fetchStart
- 首次可交互时间: domInteractive - fetchStart
- DOM Ready 时间: domContentLoadEventEnd - fetchStart
- 页面完全加载时间: loadEventStart - fetchStart
- http 头部大小: transferSize - encodedBodySize
- 重定向次数:performance.navigation.redirectCount
- 重定向耗时: redirectEnd - redirectStart
切换tab,判断当前tab是否隐藏
let vEvent = 'visibilitychange';
if(document.webkitHidden !== undefined){
vEvent = 'webkitvisibilitychange';
}
function visibilityChanged(){
if(document.hidden || document.webkitHidden){
console.info('page is hidden')
}else{
console.info('page is visible');
}
}
document.addEventListener(vEvent,visibilityChanged);
判断用户网络状态:根据用户的网络状态有针对性的进行加载
let connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
let type = connction.effectiveType;
//网络变化监听函数
connction.addEventListener('change',connectionchange);