Get Time for page to load in jQuery?
Get Time for page t开发者_如何学JAVAo load in jQuery?
What is the end of page load? window.onload
?
var start = new Date();
$(window).load(function() {
$('body').html(new Date() - start);
});
jsFiddle.
If you're supporting newer browsers, you can swap the new Date()
with Date.now()
.
With large pages or pages containing inline JavaScript, it is a good idea to monitor how long pages take to load.
The code below is different from waiting until onload is fired and only measures page load time. [+]
<html>
<head>
<script type="text/javascript">
var t = new Date();
</script>
… (your page) …
<script type="text/javascript">
new Image().src = '/load.gif?' + (new Date().getTime() - t.getTime());
</script>
</body>
<html>
load.gif can be a generic 1*1 pixel GIF. You can extract the data from your log files using grep and sed.
Also check here.
- Page load time with Jquery
- Javascript: time until page load
One good diagnostic tool to help measure page load time is [jQTester]. It is a plugin that has you place small amounts of code at the top and bottom of your page. When the page finishes loading, you get a notification saying how long it took the page to load
精彩评论