Forum: Ruby on Rails Browser caching of javascript files

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0ce4db5e1083663c575158643313852c?d=identicon&s=25 Perry Smith (pedzsan)
on 2011-08-07 19:49
I'm using the latest Firefox and firebug with Rails 2.3.11 (and Ruby

I see my javascript assets have the last modified date, such as:


which has been the case for a while.  What I just noticed is that
Firefox (according to Firebug) is fetching this for each request.  This
is for a Rails server running in "production" mode.  The browser's
caching settings are normal (true for things like
browser.cache.disk.enable and browser.cache.memory.eable).

With my super small internet connection, pulling over prototype,
scriptaculous, and all its friends is a significant hit -- plus, it just
doesn't make any sense for it to do it every time.

The underlying environment is Apache and Thin (both relatively recent).
It seems like either the browser should not attempt to fetch it at all
(which it tends to do if the ?123456789 isn't there) or the server
should be returning 304 (not modified).

Is this normal?  What options do I have to change this?

Thank you,
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2011-08-07 20:42
(Received via mailing list)
On Aug 7, 6:49pm, Perry Smith <> wrote:
> caching settings are normal (true for things like
> Is this normal? What options do I have to change this?

You're actually getting a 200 request back with the full file?

If you want the browser not to bother even fetching the file then you
need to set headers saying that content can be cached.

Something like

<Location /javascripts>
    ExpiresActive on
    ExpiresDefault "access plus 21 days"

should tell browsers that they can cache stuff from javascripts for up
to 21 days.
For stuff like prototype, scriptaculous etc you might want to consider
using the copies hosted by ( ).
That way those files come from google's network rather than yours and
they take care of setting all the right caching headers (as well as
having a cdn that is spread worldwide)


This topic is locked and can not be replied to.