Rails 3 Asset Pipeline + Apache + Phusion Passenger

I am using the Rails 3.1 w / asset pipeline, phusion 3.0.x and apache 2.2.17.

The documentation for the configuration http://guides.rubyonrails.org/asset_pipeline.html in section 4.1.1 says that I need to add a section to the apache configuration:

<LocationMatch "^/assets/.*$"> # Some browsers still send conditional-GET requests if there 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 guess Phusion Passenger just got it right ... or was I sloppy in non-RTFM? If I want to use fingerprints, do I need to add this to the apache configuration?

+6
source share
1 answer

If you want the full benefits of the asset pipeline, you really need to add this to your Apache configurations. Without this section, your Apache configuration most likely indicates that browsers do not cache assets, which leads to an unnecessary number of rounds between the browser and your server.

For this to work, you may need to include a few more Apache modules. For this:

 sudo a2enmod # Choose headers sudo a2enmod # Choose expires sudo service apache2 restart 

To debug the setup, I recommend using the Live Headers Firefox plugin. Using this, ask the resource URL (for example, http://mysite.com/assets/application-8a0ae0b2d708f797674b7123c37501ba.css)and view the cache headers before and after making this change. Find an example resource URL by doing View Source on any page.

After the change, you should see that the cache expiration date will be set to one year in the future.

+9
source

Source: https://habr.com/ru/post/901044/


All Articles