2

I'm using jquery .load() to load some external(but within same domain) resourses into the page.

As this action is not visible through FireBug Network / Chrome Network console - how can I measure the time of loading?


EDIT:

If running locally ( not localhost ) FireBug will not record this action.

Make sure you are testing this using WAMP / XAMPP (localhost) or on an on-line server.

Iladarsda
  • 10,640
  • 39
  • 106
  • 170

4 Answers4

2

Using difference in time:

var startDate = new Date();
var startMilliseconds = startDate.getTime();

$('mycontainerselector').load('myurl.html', function() {
    console.log(new Date().getTime() - startMilliseconds);
});

some corrections may be needed :)

Samich
  • 29,157
  • 6
  • 68
  • 77
  • Very clever! Is the result in ms? – Iladarsda Sep 15 '11 at 10:21
  • According to [W3C](http://www.w3schools.com/jsref/jsref_gettime.asp) yes _(getTime() returns the number of milliseconds since 01.01.1970)_, but I didn't checked it. – Samich Sep 15 '11 at 10:23
  • 1
    Funny story - I get two different results - 25ms using this `count and log` method and 30ms reported by FireBug / Netword. – Iladarsda Sep 15 '11 at 10:31
2

.load() makes an AJAX call and it is visible in the firebug console, are you sure you are doing everything in the correct way?

Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
1

another way of measuring this is the following:

var startDate = new Date();
var startMilliseconds = startDate.getTime();

$('#stuff').ajaxStop(function() {
    console.log(new Date().getTime() - startMilliseconds);
});
Zia
  • 2,735
  • 3
  • 30
  • 27
1

you can use console.time() and console.timeEnd()

console.time('loading ajax');
$('#stuff').load('url.html', function() {
   console.timeEnd('loading ajax');
});

it will print "loading ajax: 1247ms" in the console.

roselan
  • 3,755
  • 1
  • 20
  • 20