Tuesday, July 22, 2008

Quick solution to Ajax caching issue

I got this quick fix solution to Ajax caching issue from the following site. Thought of sharing this.

http://radio.javaranch.com/pascarello/2005/10/21/1129908221072.html

The question: The Ajax request is grabbing the cached page from the previous request, how do I stop this from happening? Well I have seen some fancy approaches by people, but there is one easy solution that works: a random query string value appended to the request.

So how and why does this work. Well it simple terms, when the browser looks at the destination, if it has a match, then it uses the data it has. Now this is great for when you are going to a static website, but since we are looking for new data, it sucks. By appending a random value to our parameters that we are sending back, it forces the browser to say, "Stop the press! We got new info here! Lets go get the data!"

No comments:

Post a Comment