Browser-Side Caching with Apache

Browser-side caching relies on HTTP headers to know whether or not the content it has in its local cache is still valid. If it is, then it uses the local copy, rather than downloading the file from the server again. Many sites like whysoslow.com will report that you’re missing this HTTP header on your static files, which is normal, since you aren’t explicitly setting that in the files, since they’re mostly images and the like. In order to improve browser-side caching of your static content you could add mod_expires to your Apache configuration. This would add the necessary HTTP headers to make browser-side caching of your static content possible.

Install mod_expires and add the following to the .htaccess:

# Deflate output configuration
#
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/javascript
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

ExpiresActive On
ExpiresDefault “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType text/css “access plus 1 month”

AddType image/x-icon .ico
ExpiresByType image/x-icon “access plus 1 year”
ExpiresByType image/ico “access plus 1 years”

About vicki

Welcome to the Sovereign Republic of Vickistan. I am the President here. Lucky me! No taxes or laws yet. Lucky you!
This entry was posted in Apache, Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *