This is what I use for header / caching management, I am not an Apache professional, so let me know if there is room for improvement, but I know that it works well on all my sites for some time now.
mod_expires
http://httpd.apache.org/docs/2.2/mod/mod_expires.html
This module controls the setting of the Expires HTTP header and the max-age directive of the HTTP Cache-Control header in server responses. The expiration date can be set in relation to the time during which the source file was changed, or the client’s access time.
These HTTP headers instruct the client about the validity of the document and its storage. If cached, the document can be extracted from the cache, and not from the source, until this time passes. After that, the copy of the cache is considered “expired” and is invalid, and a new copy must be obtained from the source.
# BEGIN Expires <ifModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType text/html "access plus 1 seconds" ExpiresByType image/gif "access plus 2592000 seconds" ExpiresByType image/jpeg "access plus 2592000 seconds" ExpiresByType image/png "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds" ExpiresByType text/javascript "access plus 216000 seconds" ExpiresByType application/x-javascript "access plus 216000 seconds" </ifModule> # END Expires
mod_headers
http://httpd.apache.org/docs/2.2/mod/mod_headers.html
This module provides directives for managing and modifying the headers of HTTP requests and responses. Headers can be combined, replaced or deleted.
# BEGIN Caching <ifModule mod_headers.c> <filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> <filesMatch "\.(css)$"> Header set Cache-Control "max-age=604800, public" </filesMatch> <filesMatch "\.(js)$"> Header set Cache-Control "max-age=216000, private" </filesMatch> <filesMatch "\.(xml|txt)$"> Header set Cache-Control "max-age=216000, public, must-revalidate" </filesMatch> <filesMatch "\.(html|htm|php)$"> Header set Cache-Control "max-age=1, private, must-revalidate" </filesMatch> </ifModule> # END Caching
Trae Abell Oct 22 '12 at 16:22 2012-10-22 16:22
source share