views:

294

answers:

2

We are using gravtars for a site currently being developed in rails 2.3.4 and i am finding that the rails side tends to cache the images even after there is a change at the gravtar side. I know with javascript you can prevent caching when using thejavacript_include_tag :cache => false method, however, is there a way to prevent the cache when using the image_tag helper?

I have read around a bit and it would appear that it used to append the timestamp information after the url with some paramaters (i.e. src="image.png?123123"), but it doesn't seem to do it anymore.

Any ideas, or should i stop using those damn helpful helpers as a crutch and for once in my rails developing life write some actual code?

A: 

Are you talking about the site http://en.gravatar.com/ ?

Rails only appends cache busting timestamps to local resources. If the image is being requested from another site it won't modify the src attribute. If you need to trick your browser into not caching the remote image you'll have to set the src by hand.

-Anton

avaynshtok
+2  A: 

One option I can think of to do this would be to write a little helper that would append a "?YYYYMMDDHH" to the end of Gravatar URL's. You could generate the URL's to include year, month, day and hour. This way the browser caching should only be stale for an hour maximum.

This will increase perceived load time for your users as images would be browser cached less frequently. You could adjust any number of ways: YYYYMMDD, YYYYMMDDHHm, etc. You'll have to weigh the importance of having up-to-the-minute Gravatar images versus page rendering speeds.

Barry Hess
thanks barry, this is the approach i will have to take if indeed i do decide to take the up to date approach for users. cheers!
DrwMak