In Rails 3.1 development mode (when using the asset pipeline), images served out of assets/images are served up with the response header "Cache Control: must-revalidate".
This means that Google Chrome (and seemingly only Chrome) will attempt to re-fetch images numerous times—even during a single page view. This has resulted in screwy issues with all manners of DOM manipulation via JavaScript. To name a few:
I can completely understand that to be a reasonable thing for a development server to do. I can even understand that Chrome's refusal to cache the image, even inside a single page view, is perfectly reasonable.
So, is there a way to change the Cache Control header that Rails applies to image responses in development?
Update: as suggested by a couple people, an even more interesting question is why does Chrome attempt to re-fetch the images multiple times within a pageview when no other browsers seem to? (And why isn't this causing issues for other developers?)
Update x2: I'm not going to submit this as an answer because it's just a workaround that happens to be sufficient for my purposes, but we were able to get around this issue by precompiling assets and then discarding the precomplied CSS & JS. (This will require sprockets debugging to be turned to false in development.rb
.)
rake assets:precompile
cd public/assets
find . -name "*.js*" -exec rm -rf {} \;
find . -name "*.css*" -exec rm -rf {} \;
The only way I've seen to manipulate the Cache-Control header for assets is by configuring static assets with:
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With