jQuery: Disable (browser) cache for all AJAX requests

Here is a small JavaScript code snippet that uses jQuery’s .ajax() function to disable the (client side browser) cache for all subsequent jQuery AJAX calls (note that caching is enabled by default for all data types except script and jsonp):

$.ajaxSetup({
  cache: false
});

To enable caching for a special AJAX request one can override the settings be explicitly defining the cache option when calling jQuery’s .ajax():

$.ajax({
  url: [...],
  cache: true,
  success: function(){ [...] },
  [...]
});

Comments

  1. yoyo

    Great. Thanks a lot!

Leave a comment

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

*