mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 19:40:56 +08:00
perf($http): move xsrf cookie check to after cache check in $http
$http was previously checking cookies to find an xsrf-token prior to checking the cache. This caused a performance penalty of about 2ms, which can be very significant when loading hundreds of template instances on a page. Fixes #7717
This commit is contained in:
committed by
Jeff Cross
parent
9b51067516
commit
8b86d363aa
@@ -860,6 +860,25 @@ describe('$http', function() {
|
||||
|
||||
$httpBackend.flush();
|
||||
}));
|
||||
|
||||
it('should check the cache before checking the XSRF cookie', inject(function($browser, $cacheFactory) {
|
||||
var testCache = $cacheFactory('testCache'),
|
||||
executionOrder = [];
|
||||
|
||||
spyOn($browser, 'cookies').andCallFake(function() {
|
||||
executionOrder.push('cookies');
|
||||
return {'XSRF-TOKEN':'foo'};
|
||||
});
|
||||
spyOn(testCache, 'get').andCallFake(function() {
|
||||
executionOrder.push('cache');
|
||||
});
|
||||
|
||||
$httpBackend.expect('GET', '/url', undefined).respond('');
|
||||
$http({url: '/url', method: 'GET', cache: testCache});
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(executionOrder).toEqual(['cache', 'cookies']);
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user