I am trying to understand why AngularJS $http service success callback give me a slower response time compare to the $.ajax success callback.
I trigger this code 5 times with differents json files :
if(isJquery){
$.ajax({
type : 'GET',
url : url1,
async : true,
beforeSend: function(xhr){
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
xhr.setRequestHeader('Access-Token', token);
},
success : function (returnData) {
Chrono.getTime('ajax success')
},
error : function (xhr, textStatus, errorThrown) {
},
complete : function (){
}
});
}else{
var configuration = {
method: 'GET',
url: url1
};
var headers = {};
headers['Content-Type'] = 'application/json;charset=UTF-8';
headers['Access-Token'] = token;
configuration.headers = headers;
$http(configuration)
.success(
function (data, status, headers, config) {
Chrono.getTime('httpService success')
})
.error(function (data, status, headers, config) {
});
}
With ajax I received this response time :
ajax success = 332
ajax success = 335
ajax success = 336
ajax success = 337
ajax success = 361
with $http :
httpService success = 325
httpService success = 357
httpService success = 380
httpService success = 430
httpService success = 538
I noticed that the response time increase even more when there is data or function to process in the success callback. It's like Angular is hanging before processing the other sucess callbacks...
I know Angulars is using promises to handle callbacks... could it explain why response time is increasing ? Maybe I didn't understand how to best use $http service.
I am open to suggestion and anaylsis.
Thanks for your time.