Browser caching of javascript files

I’m using the latest Firefox and firebug with Rails 2.3.11 (and Ruby
1.9.1).

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

javascripts/prototype.js?123456789

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,
pedz

On Aug 7, 6:49pm, Perry S. [email protected] 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 ( Gehostete Bibliotheken  |  Hosted Libraries  |  Google for Developers ).
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)

Fred

Fred