HTTP 1.1 contains powerful cache-control mechanisms to allow clients to place requirements on the operations of network caches. The specific method will be discussed below.(this post is specific to Apache, external links talk about using ASP, IIS, PHP, perl, CGI, Coldfusion, etc.)

Browsers automatically cache files, but they do so in a "must-revalidate" way. That means that they cache the files on your server, but every single time you use that cache by going back to the cached page, your browser send a 301 If-Modified header to check and see if you have modified the cached file since that time. Basically most images, css, javascript, and other files can be optimized for faster loading by telling your visitors browsers to cache them for a certain period of time. The default behaviour is to check the last-modified and/or the Etag headers of the file EVERY time it is requested.

By employing the methods in this article you can totally eliminate these unneccessary 301s and dramatically speed up the loading and rendering of your site. When you implement the caching method described in this article, you can specify that certain files or filetypes be cached for a specific amount of time. These files are then cached by your site visitors and they do not send the If-Modified-Since until the set cache time has completed.

WarningsYou should never need to go over a MONTH. (I go a year for .pdf, .ico, .flv, .mp3)

And once you set an expiration date and a visitor sees it, the visitor will not even attempt to check for a new version until that expiration.. so start out with small expiration lengths!

jdMorgan wrote:Note that despite its name, "no-cache" does not prevent caching. It is taken to mean that the object must be revalidated. But then we add another layer of nonsense, in that this is considered a "weak revalidation" request, and caches can ignore it under very-poorly-defined circumstances. In order to force "strong revalidation," you have to use "no-cache, must revalidate". But even then... Large and big-headed ISPs like AOL won't obey that strong revalidation, so you have to pound them over the head with, "private, must-revalidate", telling them not to cache the object in their network caches at all.

Does my Apache Server have the modules?The modules need to be built into Apache; although they are included in the distribution, they are not turned on by default. To find out if themodules are enabled in your server, find the httpd binary and run httpd -l; this should print a list of the available modules. The modules we’relooking for are mod_expires and mod_headers.

If they aren’t available, and you have administrative access, you can recompile Apache to include them. This can be done either by uncommenting the appropriate lines in the Configuration file, or using the -enable-module=expires and -enable-module=headers