views:

76

answers:

2

I develop a simple overlay to preview image in full size.

I use "cache: false" to prevent caching.

The code is simple:

$.ajax({
   url: urlFull,
   cache: false,
   success: function(html){
      // display image
   },
   error: function(XMLHttpRequest, textStatus, errorThrown ) {
      // display error
   }
});

The problem is - When image file will be replaced by another, browser will always show the old one, regardless of "cache: false" option was set.

This issue appears under Safari 5.0 (6533.16) and Chrome 5.0.375.99.

In Firefox 3.6.3 it works as expected (no caching)

I cannot control server-side logic, because i preload a regular file, without calling controller actions in rails.

Is there any workaround of this problem ? Maybe, i can intercept the response with Rails server and tweak some headers ? ... I developing under localhost.

Thanks.

+1  A: 

As a "dirty" solution try adding a time-stamp to your URL GET parameters.

spektom
+1 - It isn't a dirty solution, it is the only way I know of that will work on all browsers. Now, if you are willing to use a `POST` instead of `GET`, then that will also prevent caching.
Geoff Lanotte
I have not found the timestamp in documentation. How can i set it ?
AntonAL
spektom
A: 

I have tried to use

data: { timestamp: new Date().getTime() }.

It does not work.

In developer's panel of Safari i found, that the request string looks like this:

"http://path_to_the_image.png?_=1279789134612".

I have added the "_" parameter:

data: {_: new Date().getTime()}

and got following url:

"http://path_to_the_image.png?=1279789134612&=1279789245466".

Also, i have tried to use "timestamp", "tstamp", "t"; setting "0", "9999999999999" ... all gives no result...

It seems, like i cannot control the timestamp, that internally is setted in $.ajax ...

AntonAL