我的团队希望研究当前系统中的网络延迟。为此,我们希望记录网络事件并异步获取数据,以便接口的使用不会影响当前的网络调用。
我相信这个API已经在浏览器中记录事件,所以让我们忘记异步,根本就没有网络调用。
使用该界面,我能够开发以下GitHub中托管的脚本:
/*
* This function logs properties using Performance Timing interface info for various events which occur during loading and use ofo current page
* Events recorded -
* 1 -Time taken to download the webpage from server
* 2- Time taken to render the webpage
* 3- DNS lookup timing
* 4- TCP connection establishment timing
* 5- Response loading timing
*
* For more info visit -
* https://www.w3.org/TR/navigation-timing/#processing-model#processing-model
* https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming
* https://www.html5rocks.com/en/tutorials/webperformance/basics/
*
*
*/
window.onload = function()
{
console.log( "Performance API - " );
console.log("Time taken to download the webpage from server : " + (window.performance.timing.responseEnd - window.performance.timing.navigationStart) + " ms" );
console.log( "Taken to render the webpage is : " + (window.performance.timing.loadEventStart - window.performance.timing.domLoading) + " ms" );
var item = window.performance;
var timing = item.timing;
var navStart = timing.navigationStart;
var redStart = timing.redirectStart - navStart;
var redEnd = timing.redirectEnd - navStart;
var dnsStart = timing.domainLookupStart - navStart;
var dnsEnd = timing.domainLookupEnd - navStart;
var tcpStart = timing.connectStart - navStart;
var tcpEnd = timing.connectEnd - navStart;
var reqStart = timing.requestStart - navStart;
var loadStart = timing.responseStart - navStart;
var loadEnd = timing.loadEventStart - navStart;
console.log(
'DNS lookup = ' + (dnsEnd - dnsStart) + 'ms ' +
'Established TCP connection = ' + (tcpEnd - tcpStart ) + 'ms ' +
'Response loading = ' + (loadStart - reqStart ) + 'ms '
);
}
https://github.com/jimmy17x/HTMLPerformanceInterface/
请告诉我在系统中连接此代码的影响是什么,最重要的是,如果使用此API对网络有任何依赖性?