Angular IE Caching issue for $http

Angular IE Caching issue for $http

All the ajax calls that are sent from the IE and Edge are cached by Angular and I don’t get the right data from the server . Just because the http request is the same, the response is not gonna be always the same. This issue exist specifically for get requests. And it seems to me like a known bug which Microsoft needs to fix at some point.
In the meanwhile here is a simple and effective solution:

app.config([
    '$httpProvider',
    function($httpProvider) {
        if (!$httpProvider.defaults.headers.get) {
            $httpProvider.defaults.headers.get = {};
        }
        $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
        $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
    }
]);

Leave a Comment

Your email address will not be published. Required fields are marked *