I ran tests on my website using Google's PageSpeed and it recommends that I "Leverage browser caching" and provided the following resource:
http://code.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching
This resource never explains how to actually change the expiration date of my http headers. Do I do this through .htaccess? I would like to set the caching for as long as possible (without violating Google's policy of a year max).
Any advice on recommended settings (for a custom php-driven social networking community) would be greatly appreciated.
In your root's .htaccess:
And follow by:
This is the exact same code I use on every property I manage and offers me (and PageSpeed) the most satisfying results. One may argue on specific rules, that's why I said that it satisfies me, but it certainly satisfies PageSpeed.
It can be done with both htaccess and php. Typically you wouldn't want to force caching the actual html since its dynamic database driven content (it can be done with the
header()
php function if needed). What you want to cache is external css & javascript, and image files.See here for an .htaccess solution: http://www.askapache.com/htaccess/apache-speed-expires.html