When checking an website performance via Google Developers Tool, in some cases it returns an warning under Leverage browser caching. The following solution was tested on WordPress platform but should work on any website. The funny thing in this test/tools is that Google itself does not always follow protocol implemented by this test, see the results bellow.
Leverage browser caching
Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.
Suggestions for this page
The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:
- http://www.reboot.ro/…/tabcontent.css (expiration not specified)
- http://www.reboot.ro/…/tabcontent.js (expiration not specified)
- http://www.reboot.ro/…/logo.gif (expiration not specified)
- http://www.reboot.ro/…/logo.png (expiration not specified)
- http://connect.facebook.net/en_US/all.js (5.1 minutes)
- https://apis.google.com/js/plusone.js (30 minutes)
- http://www.google-analytics.com/ga.js (12 hours)
One way to overcome this is by modifying the .htaccess file, found in the /public_html/ root with following content:
# BEGIN Browser caching # Turn on Expires and set default expires to 3 days ExpiresActive On ExpiresDefault A259200 # Set up caching on media files for 1 month <filesMatch ".(ico|gif|jpg|jpeg|png|flv|pdf|swf|mov|mp3|wmv|ppt)$"> ExpiresDefault A2419200 Header append Cache-Control "public" # Set up 7 days caching on commonly updated files <filesMatch ".(xml|txt|html|js|css)$"> ExpiresDefault A604800 Header append Cache-Control "private, must-revalidate" # Force no caching for dynamic files <filesMatch ".(php|cgi|pl|htm)$"> ExpiresDefault A0 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" # END Browser caching