4

I am trying to bypass aggressive IE10 caching by setting Cache-control header to some of my GET requests.

However, it does not seem to have a desired effect. Below you can find the code I use. Names are sanitised a bit.

service.factory('service', ['$resource',
    function($resource) {
        return $resource(url + '/:year', {year : '@year'},
            {'GET': {
                headers : {
                    'cache-control': 'private, max-age=0, no-cache' }
            }});
    }
]);

4 Answers 4

3

I have put the cache control inside my config.

$httpProvider.defaults.headers.common['Cache-Control'] = 'no-cache, no-store, must-revalidate';
$httpProvider.defaults.headers.common['Pragma'] = 'no-cache';
$httpProvider.defaults.headers.common['Expires'] = '0';    

with this, I was able to cache for IE but I had put in module config before config router provider.


Updated

may be something like this, I am not totally sure about it. So you can try.

service.factory('service', ['$resource',
    function($resource) {
        return $resource(url + '/:year', {year : '@year'},
            {'GET': {
                headers : {
                    'cache-control': 'no-cache, no-store, must-revalidate',
                    'Pragma' : 'no-cache',
                    'Expires' : '0'
                }
            }});
    }
]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for response, but it would affect all GET requests, wouldn't it?
2

THe suggested solutions did not help me, but give food for thought. Posting for posterity the config that eventually solved my problem.

var config = {
            headers : {
                "Pragma": "no-cache",
                "Expires": -1,
                "Cache-Control": "no-cache"
            }
        };

Comments

0
service.factory('service', ['$resource',
    function($resource) {
        return $resource(url + '/:year', {year : '@year'},
            {'GET': {
                headers : {
                    "Pragma": "no-cache",
                    "Expires": -1,
                    "Cache-Control": "no-cache"
                }
            }});
    }
]);

Comments

0
$http.get("your api url", {
    headers: {
        'If-Modified-Since': '0',
        "Pragma": "no-cache",
        "Expires": -1,
        "Cache-Control": "no-cache, no-store, must-revalidate"
    }
})

This one will disable cache for every browsers.

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.