2011-09-22 63 views
1

我正在开发中,我要检查每一个网页或控件加载时间的加载时间一个Web应用程序..

服用多少时间来加载整个页面的内容是什么?
我想计算asp.net页面加载时间以微秒/秒为单位,如何使用jquery/Javascript计算Asp.net页面的加载时间?

如何才能知道使用Javascript/jquery?

+0

你通过Ajax加载页面?如果你想要的时间页面是浏览器中的主页面,那么我认为它不能完成,但是如果你想看看在一个框架或ajax中加载脚本需要多长时间,那么这可能是 – galchen

+0

@galchen no我使用jquery函数来使用webservice加载页面...没有使用ajaxtoolkit。 –

回答

5

以下脚本可以帮助您;

<SCRIPT LANGUAGE="JavaScript"> 
//calculate the time before calling the function in window.onload 
beforeload = (new Date()).getTime(); 
function pageloadingtime() 
{ 

    //calculate the current time in afterload 
    afterload = (new Date()).getTime(); 
    // now use the beforeload and afterload to calculate the seconds 
    secondes = (afterload-beforeload)/1000; 
    // If necessary update in window.status 
    window.status='You Page Load took ' + secondes + ' seconde(s).'; 
    // Place the seconds in the innerHTML to show the results 
    document.getElementById("loadingtime").innerHTML = "<font color='red'>(You Page Load took " + secondes + " seconde(s).)</font>"; 

} 

window.onload = pageloadingtime; 
</SCRIPT> 

参考来自:http://www.dreamincode.net/code/snippet1908.htm

如果你只是想检查的时候使用火狐萤火虫这显示excution时间。 像这样enter image description here

+0

Firebug。绝对是Firebug(或Chrome的等同物)。 – Bojangles

+0

非常感谢@pranay_Rana。谢谢你的好例子。 –