使用 Jquery 的页面加载时间 [英] page load time with Jquery
问题描述
我要计算页面加载时间;这意味着从第二个 0(加载了一个小的 jquery 片段)到第二个 x,当整个页面被加载时.
I want to calculate the page load time; This means from second 0 (a little jquery snippet was loaded) to second x, when the whole page is loaded.
我想知道是否有人对它有过使用经验,也将提供如何正确实施它的想法.
i wonder if any one had an experience with it, also ideas how to implement it correctly will be apperciated.
拜托我不需要扩展,我已经有了firebug,我需要一个js解决方案
谢谢:)
推荐答案
正如其他人所提到的,这不会非常准确.但这应该是合理的.
As others have mentioned, this is not going to be terribly accurate. But this should work reasonably.
在你的中,即尽可能早:
In your <head>
, i.e., as early as possible:
<script>
var startTime = (new Date()).getTime();
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
$(window).load(function () {
var endTime = (new Date()).getTime();
var millisecondsLoading = endTime - startTime;
// Put millisecondsLoading in a hidden form field
// or Ajax it back to the server or whatever.
});
</script>
关键是这种行为,来自 jQuery 文档:
当绑定到 window 元素时,事件在用户代理时触发完成加载一个内的所有内容文档,包括窗口、框架、对象和图像.
When bound to the window element, the event fires when the user agent finishes loading all content within a document, including window, frames, objects and images.
这篇关于使用 Jquery 的页面加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!