So Rails time stamping is great. I’m using it to add expires headers to all files that end in the 10 digit timestamp. Most of my images however are referenced in my CSS. Has anyone come across any method that allows for timestamps to be added to CSS referenced images, or some funky re-write rule that achieves this? I’d love for ALL images in my site, both inline and in css to have this timestamp so I can tell the browser to cache them, but refresh any time the file itself changes.
I couldn’t find anything on the net regarding this and I can’t believe this isn’t a more frequently discussed topic.
I don’t think my setup will matter because the actual expiring will hopefully happen the same way, based on the 10 digit timestamp, but I’m using apache to serve all static content if that matters
You can append the actual timestamp of each image file by getting the file modification time like this:
(There’s probably a more elegant way to write this, my ruby chops are still weak!)
Now the hack’s getting ugly, though… you’d think there would be a more Rails-like way to do this.