As far as I know, Rails3 can "optimize" the caching of images, javascripts, and style docum开发者_如何学编程ents by appending a "?ID" string on the end of the filename, such as in: /stylesheets/normalize.css?1310531409.
However, if I use firebug to check my page's loading, here is what appears:
I am using RoR3 on Heroku, working on a Cedar Stack.
How can I manipulate the expiration time of the images/stylesheets/javacripts that are sent? Currently, they seem to expire in the moment they are sent, which is kind of non-sense. I am facing difficulties on accomplishing this on Heroku, operating on a Cedar Stack.
Thanks very much.
I recommend you use Jammit, more specifically the jammit-s3 gem. This will allow you to push your all assets to s3 and the linked gem has an s3 cache control setting. Used in combination with rails' asset_host configuration you can have an assets.yourdomain.com subdomain which may help page load times and will reduce your slug size.
The asset ID rails adds isn't to force caching, it's a cache buster. The numbers (by default) are the last modified date of the file. If you update the file, the numbers change, forcing browsers to get the new version. It doesn't mean that if the number is the same, the browser won't try to fetch it anyway.
Setting the expiry time is more in the domain of the server (presumably apache or nginx). You can configure them to have different cache control settings - a quick google for either will give you loads of tips for how to go about it.
精彩评论