How do I prevent a jQuery Ajax request from caching in Internet Explorer?
-
1Using POST instead of GET prevents caching. http://stackoverflow.com/questions/6216234/disable-ajax-caching – Prashant Agarwal Jul 18 '13 at 18:44
-
8YSlow and Chrome dev tools will warn you if you use POST requests for AJAX - generally GET should be the preferred method unless you really need to POST. – Pawel Krakowiak Nov 27 '13 at 13:25
-
Here is Your answer : [disable Cache in IE](http://stackoverflow.com/questions/33019108/how-to-remove-microsoft-edges-cache-using-php-or-javascript#autocomment71335868) – S.Mohamed Mahdi Ahmadian zadeh Feb 07 '17 at 06:59
6 Answers
You can disable caching globally using $.ajaxSetup()
, for example:
$.ajaxSetup({ cache: false });
This appends a timestamp to the querystring when making the request. To turn cache off for a particular $.ajax()
call, set cache: false
on it locally, like this:
$.ajax({
cache: false,
//other options...
});

- 623,446
- 136
- 1,297
- 1,155
-
2Wish I would have seen this global setup item before. Just saved me from having to update dozens of individual calls. – James Skemp Nov 29 '12 at 03:21
-
2I know this is an old answer, just wondering if this affects all ajax like calls (ajax, get and post) or only specific ajax calls? – Lumpy Jan 26 '13 at 19:21
-
6@Lumpy, according to [jQuery.ajax() documentation](http://api.jquery.com/jQuery.ajax/), `cache: false` will only work correctly with HEAD and GET requests. Also, if you set `cache: false` in `$.ajaxSetup`, according to [jQuery.ajaxSetup() documentation](http://api.jquery.com/jQuery.ajaxSetup/), it will "set default values for future Ajax requests." So yes, it will disable cache for all future HEAD and GET AJAX requests. – John Washam Jun 07 '13 at 21:29
-
11A word of caution: this adds "?_=somenumber" to your URL. Make sure your back end can ignore the "_" in the URL's query parameters. – Sep 26 '13 at 19:34
-
4+1 for `cache: false`. Turning off caching globally seems like overkill, but having control per request is perfect. Thanks – iCollect.it Ltd Apr 16 '14 at 10:17
-
Default value of 'cache' configuration is true. Interestingly, I'm observing that all browsers except Microsoft edge are ignoring this configuration in the ajax calls. I had not mentioned it explicitly while making the ajax call so my assumption is that it must be taking the default value. Please advise if you all are also observing this. `$.ajax({ type: "GET", url: myUrl, contentType: "application/json", async: false, dataType: "json", success: function (data) { searchResults = data; } } })` – RBT Mar 17 '16 at 11:51
-
2I think all browsers don't cache ajax by default. It's only IE that does. This answer just saved me. Freaking IE, always has to be different. – Leeish Aug 18 '16 at 22:48
-
For some reason locally disabling caching did not solve the problem for IE 11, only global cache disabling did. I'm using jQuery 1.7.2. – simon Jun 12 '17 at 08:48
-
This will add "&_=
" to the end of your URL. Not sure why guaranteeing a unique URL will prevent caching, especially if IE is set to "Never check for newer version of stored pages" for example. Answer is it won't. With this setting IE still caches the results of my Ajax get calls. This is not a solution. – user3335999 Mar 06 '19 at 16:33 -
Even global cache disabling doesn't seem to be working with IE 11. Has anyone had the same problem as me ? – badri Apr 12 '19 at 10:47
If you set unique parameters, then the cache does not work, for example:
$.ajax({
url : "my_url",
data : {
'uniq_param' : (new Date()).getTime(),
//other data
}});

- 1,012
- 11
- 8
-
13That is what the `cache` parameter already does behind the scenes. – Jose Rui Santos Mar 06 '13 at 12:33
-
The ajaxSetup code above did not work for me, didn't spend much time on figuring out why. Global variables are bad, and sometimes you want to cache. This answer is best in my opinion. – bladefist Jul 23 '13 at 15:50
-
@bladefist you seem to have hit the same problem as me. Do you know if there are other options apart from changing data to make IE stop caching ? The reason i'm asking is because my requests actually don't make use of 'data' and all data goes alongwith the URL. – badri Apr 12 '19 at 13:12
-
1Actually, this is surely what cache should be doing behind the scenes as per this information from - http://api.jquery.com/jquery.ajax cache (default: true, false for dataType 'script' and 'jsonp') Type: Boolean If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. – badri Apr 12 '19 at 14:04
-
@bladefist It clearly says that it is going to append a timestap to the GET params. so wonder why the code provided by Koss works for you and disabling local or global cache doesn't? – badri Apr 12 '19 at 14:08
-
If you do not use parameters, you can add a unique parameter to the URL: $.ajax({url : "my_url?uniq_param="+ (new Date()).getTime()}); – Koss Apr 14 '19 at 05:46
Cache-Control: no-cache, no-store
These two header values can be combined to get the required effect on both IE and Firefox

- 46,981
- 12
- 120
- 134
-
12The problem is that IE doesn't always listen to this, unfortunately :) – Nick Craver Nov 29 '10 at 13:05
-
1@Nick, is it sure? i didn't test this Cache-Control. Is Jquery Ajax chache is work on all browser? – Nov 29 '10 at 13:19
-
7It *should* work on all browsers, yes...but sometimes IE just likes to cache the hell out of things – Nick Craver Nov 29 '10 at 13:20
-
@Nick - I set the ajax cache to false.But the ajax success message didn't get in IE and also in FF. Can you please verify my code? is my code is wrong ? Thanks var ajaxfile = base+"index.php/msc/popup_view/"+obj+"/"+id+"/"+no_tab; $.ajax({type: "GET",url: ajaxfile, //contentType: "application/json; charset=utf-8", cache: false, success: function(msg){ $("#popup").html(msg); } }); – SABU Nov 30 '10 at 04:37
-
I've just confirmed that IE11 ignores this header. Chrome threw a CORS error as well. – Lenin Nov 07 '18 at 15:20
Here is an answer proposal:
http://www.greenvilleweb.us/how-to-web-design/problem-with-ie-9-caching-ajax-get-request/
The idea is to add a parameter to your ajax query containing for example the current date an time, so the browser will not be able to cache it.
Have a look on the link, it is well explained.

- 324
- 4
- 15
-
13That is what the `cache` parameter already does behind the scenes. – Jose Rui Santos Mar 06 '13 at 12:34
you can define it like this :
let table = $('.datatable-sales').DataTable({
processing: true,
responsive: true,
serverSide: true,
ajax: {
url: "<?php echo site_url("your url"); ?>",
cache: false,
type: "POST",
data: {
<?php echo your api; ?>,
}
}
or like this :
$.get({url: <?php echo json_encode(site_url('your api'))?>, cache: false})
hope it helps

- 31
- 4
This is an old post, but if IE is giving you trouble. Change your GET requests to POST and IE will no longer cache them.
I spent way too much time figuring this out the hard way. Hope it helps.

- 41
- 1
-
I don't think you should be misusing HTTP actions. Settings `cache:false` on a case-by-case basis is the way to go. – tommybond May 25 '17 at 22:43