Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Calculate Page Load Time in JavaScript

Apr 3, 2013
Introduction

Here I will explain how to calculate page load time in JavaScript, jQuery.

Description:
  
In previous articles I explained jQuery custom right click context menu, JavaScript Check internet connection,
jQuery Get Cursor position, jQuery select all the text from textarea and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to calculate page load time in JavaScript, jQuery.

If we want to calculate page load time in we need to write the code like as shown below

JavaScript Code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery calculate page load time in javascript</title>
<script type="text/javascript">
var beforeload = new Date().getTime();
window.onload = gettimeload;
function gettimeload() {
var aftrload = new Date().getTime();
// Time calculating in seconds
time = (aftrload - beforeload) / 1000
document.getElementById("lbltxt").innerHTML = "Your Page took <font color='red'><b>" + time + "</b></font> Seconds to Load";
}
</script>
</head>
<body>
<div>
<label id="lbltxt" />
</div>
</body>
</html>
jQuery Code


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery calculate page load time in javascript</title>
<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var beforeload = new Date().getTime();
window.onload = gettimeload;
function gettimeload() {
var aftrload = new Date().getTime();
// Time calculating in seconds
time = (aftrload - beforeload) / 1000
$("#lbltxt").text(time);
}
});
</script>
</head>
<body>
<div>
your Page took
<label id="lbltxt" style="font-weight:bold; color:Red"></label>
Seconds to Load
</div>
</body>
</html>
Live Demo

For Live Demo Check below time it’s based on the time taken to load this page


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

Anonymous said...

nice article,

Thanks

Irtekaz Ahmed Khan said...

amezing load page time .

Abhinavsingh993 said...

You are great and Work is always greater than the thought may I be 1% of your dedication

Unknown said...

this will work only in firefox not in all the browsers.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.