Beating the Browser Cache

 

Unfortunately, when we attempt to make an Ajax call (especially a GET request) there is always the danger that the browser will attempt to get the result from its own web cache, rather than returning to the server for a fresh copy.

 

The browser cache exists to increase performance, by keeping a local store of web page content. Unfortunately, the nature of Ajax means that we pretty much always want our requests to go back to the server.

 

One of the easiest and most successful ways around this is to add a random parameter to our request URL. This can be added in addition to any 'real' parameter/value pairs, and ensures that the URL is unique.

 

Consider the following code:

var myurl='http://url/path/to/server_script.php';
myRand=parseInt(Math.random()*999999);
var newurl = myurl + '?rand=' + myRand;

Here we have generated a pseudorandom number to add to the URL of our server script. We can still add other parameters as required by our server script:

newurl = newurl + '&var1=' + var1;


This site is brand new and so still somewhat under construction.

Why not bookmark it and call back regularly?

Related:

Links: