1

I was wondering if HTTP Interceptors in AngularJS cause a performance hit?

I want to intercept requests and prepend the absolute URL:

angular.module('app').config(['$httpProvider', function ($httpProvider) {
    $httpProvider.interceptors.push(function () {
        return {
            request: function (config) {
                config.url = 'http://localhost:9060/' + config.url;
            }
        };
     });

}]);
1
  • 1
    That particular interceptor wouldn't cause any substantial performance problems. If you're still worried, just use performance.now() to measure the time it takes to make the call with and without the interceptor. If you test it against a real backend, be sure to take enough sample measurements. Otherwise you could measure against a mocked http backend by utilizing the ngMockE2E module (docs.angularjs.org/api/ngMockE2E.$httpBackend) Commented Jan 4, 2014 at 0:59

1 Answer 1

4

Unless you do something crazy and time-consuming within your interceptor, the actual invocation of the interceptor will be absolutely negligible in your application as compared to anything else.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.