Browser caching is generally a good thing, why download the same image again and again while you can download it once and save it on the browser? In some cases, however, this is not a wanted behavior.
The problem:
AJAX application tends to frequently ask the server for the same URL (a stock quote, application status and so forth). The AJAX application expect a response form the server while, in fact, after the first request the browser returns the cached page and the AJAX application does not work as expected. Clearing the browser cache or setting “no cache” parameters on the page does not always work.
The solution:
Add a pseudo-random parameter to the URL the AJAX application is requesting. Doing so will fool the browser to think this is a new page that has not yet been cached.
For example, this is how I would add a pseudo parameter to a URL in JavaScript :
var url = “http://mydomain?myParameters=myValues&pseudoParam= “+new Date().getTime();
The Date().getTime(); returns a new value every millisecond (or so), the browser thinks this is a new page that has not been cached and requests the URL form the server.
This will hopefully work for flash and image assets that are regularly updated as well?
Thanks,
This should work fine for all media types.
Cheers
Amir Shevat
Pingback: Tip: Solving the browser caching problem of AJAX applications …
Pingback: MooTools Essentials: The Official MooTools Reference for JavaScript and Ajax Development | Ebook Online Free