Omar Abid Omar Abid - 1 year ago 111
jQuery Question

page load time with Jquery

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.

please i don't need an extension, i already have firebug, i need a js solution

thanks :)

Answer Source

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:

   var startTime = (new Date()).getTime();
<script src=""></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.

The key is this behavior, from the jQuery docs:

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download