Speed Tips: Add Cache-Control Headers
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.
Add Cache-Control Headers
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.
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 weeksHeader set Cache-Control "max-age=290304000, public" # 2 DAYSHeader set Cache-Control "max-age=172800, public, must-revalidate" # 2 HOURSHeader set Cache-Control "max-age=7200, must-revalidate"
If you are using far Future Expires Headers and Cache-Control (recommended), you can do this for these files.
Header set Cache-Control "public" Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
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 YEARHeader set Cache-Control "public" Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT" Header unset Last-Modified # 2 HOURSHeader set Cache-Control "max-age=7200, must-revalidate" # CACHED FOREVER # MOD_REWRITE TO RENAME EVERY CHANGEHeader set Cache-Control "public" Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT" Header unset Last-Modified
« Faster Form Submission and Processing with fsockopenHack WP-Cache for Maximum Speed »
Comments