I’m having trouble configuring Rails 4 to cache an image. I’m trying it out with the favicon, which may be a trivial case in terms of actual performance gain, but I would like to understand this aspect regardless.
I have been simply placing the favicon in my public
folder and serving it that way. I’m trying instead now to serve it via a simple controller so that I can use the expires_in
method in ActionController (described here).
class DocumentsController < ApplicationController
# ...
def favicon
expires_in 30.minutes, :public => true
send_file Rails.root.join('public/', 'images/', 'favicon.ico'), type: 'image/x-icon', disposition: 'inline'
end
end
But no dice. When I request the image, here is what I see in my web inspector -
So as you can see, it is not being cached. Any advice?