Using Cache-Control headers you can specify which types of proxies can cache certain content, and how long files should be cached. You can also add the must-revalidate header to force checking the ETag and or Last-Modified for the file to make sure the cache is using the current version.
Easy Apache Speed Tips Articles
- Turn On Compression
- Add Future Expires Header
- Add Cache-Control Headers
- Turn Off ETags
- Remove Last-Modified Header
- Use Multiple SubDomains
Keep in mind, if you use a far future Expires header you have to change the component’s filename whenever the file changes. So please add must-revalidate to your Cache-Control header for your .html files.
Add Cache-Control Headers
This goes in your root .htaccess file but if you have access to httpd.conf that is better.
This code uses the FilesMatch directive and the Header directive to add Cache-Control Headers to certain files.
# 480 weeks <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=290304000, public" </FilesMatch> # 2 DAYS <FilesMatch "\.(xml|txt)$"> Header set Cache-Control "max-age=172800, public, must-revalidate" </FilesMatch> # 2 HOURS <FilesMatch "\.(html|htm)$"> Header set Cache-Control "max-age=7200, must-revalidate" </FilesMatch>
If you are using far Future Expires Headers and Cache-Control (recommended), you can do this for these files.
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "public" Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT" </FilesMatch>
Without Cache-Control Headers

With Cache-Control Headers

Currently AskApache.com Uses
You can use the HTTP Header Viewer Tool to check it.
Header unset Pragma FileETag None Header unset ETag # 1 YEAR <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$"> Header set Cache-Control "public" Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT" Header unset Last-Modified </FilesMatch> # 2 HOURS <FilesMatch "\.(html|htm|xml|txt|xsl)$"> Header set Cache-Control "max-age=7200, must-revalidate" </FilesMatch> # CACHED FOREVER # MOD_REWRITE TO RENAME EVERY CHANGE <FilesMatch "\.(js|css)$"> Header set Cache-Control "public" Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT" Header unset Last-Modified </FilesMatch>
cache-control cache header apache htaccess expires max-age
Related Articles
10.29.07 at 8:13 am
Hello, very nice site, keep up good job!
Admin good, very good.
12.14.07 at 2:21 am
[...] Add Cache-Control Headers [...]