ajax synchronous vs. NON-synchronous Small Software is the Best Software

AJAX caching xml problems.

18 Oct 2006

So,

I've been using ajax for a while now, and a real problem is that the browser caches the xml like crazy, so if your not using parameters, then getting the most up to date xml can be a problem.

I looked around and found some good suggestions

  1. use a server side script to output the xml + a no-cache header

  2. add a custom header to the xml type on the web server (usually not an option)

  3. add a 'get if newer than' header to your request (set newer than = jan 1 1970)

  4. add an arbitrary random parameter to your request

Solution 4 is brilliant and simple, so just add a random guid to your request! eg :

url += "?sid="+Math.Random;

nice.