Expires header for .css

I’m using mongrel as my http server.

I was using yslow to evaluate the performance of my web site and noticed
I was downloading the .css file on every request??? I use one .css file
for the whole site and I though I would be cached?

Yslow indicates that there is no expires date/time set for the css file.

How can I tell mongrel to send an expires header with my static content?

thanks,
Scott

On Tue, May 6, 2008 at 1:55 PM, Scott D. [email protected]
wrote:

How can I tell mongrel to send an expires header with my static content?

Seems Ben Schwarz ran into the same:

http://germanforblack.com/2007/extreme-expires-headers-for-nginx-and-mongrel

Would this come into play?

$ tail -3 config/environments/production.rb

Don’t want asset-ids

Want browser caching

ENV[‘RAILS_ASSET_ID’] = ‘’ # blank.

Stephan

Stephan W.

http://stephan.sugarmotor.org
http://www.thrackle.org
http://www.buckmaster.ca
http://www.trafficlife.com
http://stephansmap.org

Is your webserver directly talking to users or are you using a proxy?

You can do this in mongrel, but generally you can configure your proxy
to
serve these files directly. It’s much faster to serve them statically.

For nginx, you can use the following…
http://wiki.codemongers.com/NginxRubyonRailsMongrel

in your server block, add the following (it will statically serve and
set
the expiration date to the maximum allowed for images, javascript and
css).

location ~* .(js|css|jpg|jpeg|gif|png)$ {
if (-f $request_filename) {
expires max;
break;
}
}

Note that you’ll have to make sure that when you change
css/javascript/images to either create a new file or add query
parameters to
defeat the caching (this is done for you in rails by default).
Additionally, if you’re dynamically rendering CSS or JS, then this will
break as well.

Also make sure that you’ve configured gzip compression for text files
(css/javascript) in nginx as well. This will also give you a big speed
improvement for most of your clients.

  • scott

Scott W. wrote:

Is your webserver directly talking to users or are you using a proxy?

At this point mongrel is talking directly to the users. I’ve been
looking at nginx but since I’m in a critical phase of development right
now I didn’t want to enter any new services at this time.

You can do this in mongrel, but generally you can configure your proxy

Yes I would like to do this in mongrel. Pre recomendation I added this
to my environmnet.rb

if defined? Mongrel::DirHandler
module Mongrel
class DirHandler
def send_file_with_expires(req_path, request, response,
header_only=false)
response.header[‘Cache-Control’] = ‘max-age=315360000’
response.header[‘Expires’] = (Time.now + 10.years).rfc2822
send_file_without_expires(req_path, request, response,
header_only)
end
alias_method :send_file_without_expires, :send_file
alias_method :send_file, :send_file_with_expires
end
end
end
but it doesn’t add the expires header to the css file.

thanks for your help in this matter,

Scott