setting Cache-Control for static assets

38 views
Skip to first unread message

craayzie

unread,
Mar 12, 2011, 4:20:19 AM3/12/11
to Radiant CMS
I've got Radiant deployed on Heroku and wanted to have it serve a
static site in addition to my Radiant site. I used rack-rewrite to map
requests for the static site to the right location but I'm not sure
how to add the proper Cache-Control response header. Could you please
point me in the right direction? Frankly, I'm not sure if rack-rewrite
is the best solution here - it was just the first one I tried which
appears to be working (aside from not sending any down-stream caching
headers).

config/environment.rb:
Radiant::Initializer.run do |config|
...
config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
send_file %r{.*}, 'public/static_site$&', :if => Proc.new { |
rack_env|
rack_env['HTTP_HOST'] =~ /www.static-site.com($|:3000)/
}
end
...

Thanks!

craayzie

unread,
Mar 12, 2011, 4:45:22 AM3/12/11
to Radiant CMS
This was almost too easy :) Again - not sure if I'm doing this the
right way but all I did was add Rack::ResponseHeaders before the
Rack::Rewrite call like so:

config.middleware.insert_before(Rack::Rewrite, Rack::ResponseHeaders)
do |headers|
headers['Cache-Control'] = 'max-age=3600'
end
Reply all
Reply to author
Forward
0 new messages