Caching CSS Issue

I have a problem I was hoping someone could shed some light on. I
noticed that with every request to my server, the css file was being
requested. I went ahead and made a static link to the css file so
there is no query string at all, but still I see the requests coming
in with each request. Do I need to do anything else (in the response
header maybe?) to make sure that browsers will cache the css?

I am on Rails 2.0.2

Thanks,
Tom

Are you running in production mode? If so, then browsers should automatically cache the CSS file, afaik.

Because of how the request to load a page works it might always include the CSS file.

I am running the server in production mode and the css is actually
being rendered by a controller (e.g. /css/my_dynamic.css). I've
noticed that each time the page is hit, I see a request for the CSS.

If you're dynamically creating the CSS file every time, it will be
requested by the browser every time. This may probably because the
modification date changes every time you generate the file. (I don't
really know--I'm just guessing.) Anyway, Ryan Bates has a screencast
you should check out:

http://railscasts.com/

In episode #88 he creates a dynamic Javascript file. In episode #89 he
caches that javascript file. Sounds like that might be just what
you're looking for.

The timestamp query string is only created if you use the rails helper
to link to the css. I went ahead and created a static link with no
query string, but the browser still won't cache it! I'm wondering if
I need to set something in the response header to tell the browser to
cache.

Thanks for pointing out the screencast, I'll definitely check them out
but I would imagine he is talking about server-side caching...

--Tom