Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Measure page loading time using javascript

You can use javascript to measure how long does it take to load your page. It's pretty simple. Get time when your page started to load, get time when it's done and do some math.

To get starting time, we need to measure it right after page started to load, it is right after opening <head> tag:

<script type="text/javascript">
before = (new Date()).getTime();
</script>

Then we create this function to do the math and put result in a <p id = "loadingtime"></p> tags with specified id  - "loadingtime".

<script type="text/javascript">
function pageload()
{
    var after = (new Date()).getTime();
    var sec = (after-before)/1000;
    var p = document.getElementById("loadingtime");
    p.innerHTML = "Page load: " + sec + " seconds.";
        
}
</script>

After that we should our function in onload event, which fires, just after page finished to load.

<script type="text/javascript">
    window.onload = function () 
    { 
        pageload();
    }
</script>

And we get page loading time.


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus