Need Browser to Not Cache Ajax Image

I am banging my head against the wall here. I have a gd-generated image
keeps being changed via ajax on my page. Since the image is generated
on querystring parameters (which don’t change) but is based on a model
is constantly changing), the browser caches the image and you have to do
page refresh to update the image. I have hacked around it by appending a
random number to the querystring, but that should make every image be
to the browser, which I don’t want to do to my clients if I don’t have
(there will be LOTS of images). What I have found online is that I need
change the headers that I am sending out. Here’s what I have and it
work. I don’t know if the headers aren’t being sent or if I am sending
wrong headers or a sickly combination of the two…

headers[‘Cache-Control’] = ‘no-cache, must-revalidate, post-check=0,
headers[‘Pragma’] = ‘public’
headers[‘Expires’] = “0”
send_data image.jpeg, :type => “image/jpeg”, :disposition => “inline”
line works

Any help would be greatly appreciated.

On 10 Jul 2008, at 09:31, Joe K wrote:

and it doesn’t work. I don’t know if the headers aren’t being sent
Any help would be greatly appreciated.
Maybe someone might come up with a header-based solution, but you
could also add an extra parameter with a timestamp to the url (don’t
know if the :with parameter of the Rails Javascript helper will do
here, I tend to write up my own Javascript instead of relying on the
Rails helpers). Rails itself uses a similar solution for the css and
javascript files that are loaded (it adds a timestamp). This would
mean your browser would send out requests like:

Best regards

Peter De Berdt


That’s almost exactly what I am doing right now, except I use
rand( rather than a timestamp (in the off chance of more
1 req/sec). I just don’t like the idea of spamming my customers’ cache
images if I don’t have to.

Thank you for your help.

On Thu, Jul 10, 2008 at 8:19 AM, Peter De Berdt
[email protected]