开发者

jQuery .load() - measure the time

开发者 https://www.devze.com 2023-04-05 14:15 出处:网络
I\'m using jquery .load() to load some ex开发者_开发技巧ternal(but within same domain) resourses into the page.

I'm using jquery .load() to load some ex开发者_开发技巧ternal(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.


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 :)


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


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.


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);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号