Reputation: 10744
I have run in production mode my smart aplication in rails 3.1 with mongodb.
I can see that page speed from firebug have a smart problem:
leverage browser caching of static, you can see in the above image:
I have check this fix but not working for me:
ROR + MVC Disable Browser Cache
I want to know how can I fix this problem for my image, css and javascript, or if there is a gem for this.
Upvotes: 4
Views: 2828
Reputation: 10744
Thank you for their response Hightechrider and miaout17.
Im using apache. I add to apache2.conf the next code:
<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>
Bue I get the next error when I try reset my server apache:
Syntax error on line 256 of /etc/apache2/apache2.conf: Invalid command 'ExpiresActive', perhaps misspelled or defined by a module not included in the server configuration Action 'restart' failed. The Apache error log may have more information.
Some idea?
Edited I found the fix for this error:
If you have a ubuntu user You can take a shortcut using a2enmod, a command that enables the module for you automatically:
sudo a2enmod headers
and then restart your server and voila :D working fine.
Upvotes: 7
Reputation: 4875
According to Asset Pipeline Guides, you need to set expiration in your web server configuration file. There are example configuration for Apache and Nginx in the guide, please read section 4.1.1 "Server Configuration" and try it.
ROR + MVC Disable Browser Cache doesn't work because you are hosting static files with web server, so the request won't go through the controller.
I think my previous answer is wrong because Expiration not specified might means browser won't cache anything, and cause very bad performance.
Previous (wrong) answer:
Upvotes: 3