Tutorial: How to stop caching with jQuery and javascript

There are many reason people want to disable or stop caching by broswer. Especially when we are dealing with dynamic content that required the latest version to be displayed on the browser. However, due to security reason there are no perfect methods in javascript that can disabled caching for all browsers. In this tutorial, i will demonstrate a few way both javascript and jQuery used to stop or disable caching by browsers.

jQuery

On the later version of jQuery v1.2 above, jQuery has provided a method to stop caching by browser with its ajax class. You can visit jQuery website to see the list of update on v1.2 and you will notice that they have now included a function to disable caching! You can either choose to control the way each individual dynamic content cached by setting the properties to true/false or you can just set a default to disabled all browser caching.

4 thoughts on “Tutorial: How to stop caching with jQuery and javascript

  1. Clay,

    Nice script for the no cache.

    RE: Javascript
    When tested with IE 8, I receive the following error:
    Expected ';'

    Char: 8 on this line: "return $(img).load(function()"

    Any ideas how to fix this?

  2. IE is very strict and troublesome. Therefore i guess the problem you are facing there is you are returning some weird stuff after you have perform a load function. The return value is definitely a jQuery object. You may want to separate that sentence. Don't think it has anything to do with caching 😀

    Clay

Comments are closed.