jQuery的页面加载时间 [英] page load time with Jquery

查看:102
本文介绍了jQuery的页面加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算页面加载时间;这意味着从第二个0(加载了一个小片段)到第二个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.

在您的<head>中,即尽早:

<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文档的 :

The key is this behavior, from the jQuery docs:

当绑定到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆