I am using Rails 3.1 w/asset pipeline, phusion 3.0.x and apache 2.2.17.
In the configuration documentation at http://guides.rubyonrails.org/asset_pipeline.html, in section 4.1.1 it states that I need to add a section to my apache config:
<LocationMatch "^/assets/.*$">
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
Header unset Last-Modified
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
I have been assuming that Phusion Passenger has just been "handling" this... or have I been negligent in not RTFM? If I want to take advantage of the fingerprinting, do I need to add this to the apache config?
If you want the full benefits of the asset pipeline, you do, indeed, need to add this to your Apache configs. Without that section, your Apache configuration is likely specifically telling browsers not to cache assets - resulting in an unnecessary number of round trips between the browser and your server.
In order to get this to work, you may need to enable a few more Apache modules. To do this:
sudo a2enmod
# Choose headers
sudo a2enmod
# Choose expires
sudo service apache2 restart
To debug your set-up, I recommend using the Live Headers Firefox plugin. Using that, specifically request an asset URL (e.g. http://mysite.com/assets/application-8a0ae0b2d708f797674b7123c37501ba.css)and look at the cache headers before and after you make this change. Find an example asset URL by doing a View Source on any page.
After the change, you should see that the cache expiration is set to one year in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With