Browser caching creating problems while updating an image on browser using Ajax


On one of the views I display an image “some_week.jpg”, which basically displays a graph for data corresponding to a particular week, by default current week.
Following is the code snippet in view which displays an image,

On this view, User has an option of selecting some other week and see the graph corresponding to it. I have implemented this using an AJAX call where the graph image is constucted using Gruff library on server side and following response is sent back from RJS,
imageTag =""
page.replace_html ,“image_place_holder”, imageTag

where, session[:user_id] =1 and @picName = “some_week.jpg”

After the response the image in the browser is still the old image, I verified on server, the new image is created in the mentioned directory but browser seem to cache the old image.

I am using Mozilla Firefox

Help is appreciated.



Timestamp the image.

image_tag should do this automatically (if you put your image in public/images):

image_tag('some_week.jpg") or you can do

The first is more elegant in that it tracks date modified time of the file to generate the asset timestamp.


Thanks Vishnu, now it works!