I have an angular application that makes HTTP GET calls to the server. It works fine on Chrome & Firefox. However, I figured out that IE caches the GET response, and after I do a POST, I need to call the same GET request and get the new updated response but IE caches it. I want to disable caching just for IE. I tried using a
'If-None-Match': '*'
request header on my GET calls, but then that disables caching for everything. Is there a way to do that conditionally for IE only? Or is there another way to disable it?
HTML
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
OR
JS
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.common = {};
}
$httpProvider.defaults.headers.common["Cache-Control"] = "no-cache";
$httpProvider.defaults.headers.common.Pragma = "no-cache";
$httpProvider.defaults.headers.common["If-Modified-Since"] = "0";
Using the above info I was able to get this working on a one-off request inside a controller instead of changing the global defaults:
var configOptions = {
headers: {
common: {
"Cache-Control": "no-cache",
"If-Modified-Since": "0",
"Pragma": "no-cache"
}
}
};
$http.get("path/to/file.json", configOptions)
.then(function (response){
//do stuff
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With