FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Home  »  Htaccess  »  Speed Tips: Add Cache-Control Headers

by 40 comments

Cache-Control Headers OnUsing 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 weeks

Header set Cache-Control "max-age=290304000, public"


# 2 DAYS

Header set Cache-Control "max-age=172800, public, must-revalidate"


# 2 HOURS

Header 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

No Cache-Control Headers

With Cache-Control Headers

Cache-Control Headers On

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

Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified


# 2 HOURS

Header set Cache-Control "max-age=7200, must-revalidate"


# CACHED FOREVER
# MOD_REWRITE TO RENAME EVERY CHANGE

Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified

Tags

March 10th, 2008

Comments Welcome


Related Articles


My Online Tools
Popular Articles


Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman









[hide]

It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

+Askapache | askapache

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain