Using cache expire headers can help you improve the speed of your website. The browser stores certain website elements in its cache and will keep loading them from its cache until they are remotely removed or the attached date is expired.
I myself use a simple code snippet in my .htaccess file to ensure all the filetypes I decide to attach an expire-header to are set in one and the same place. The code is set to all file-extensions mentioned in the code and you can manually add any filetype you want. Simply paste the following code to your main .htaccess file
Header set Expires "Thu, 15 Sep 2011 20:00:00 GMT"
You can remove any unsed file extensions from the code. This simple code will do the trick for all the elements on your website. You can also break up the code and set different expire headers for different groups of file-extensions.
The expire header uses the timestamp format as shown in the code. You can also set it to 0 which will tell the browser to instantly refresh all mentioned elements.
Test your speed results with Google Speed or YSlow.
If you want to set an expire header on you HTML, I recommend using something like the following PHP code in your header.
<?php header("Content-type: text/html; charset: ISO-8859-1"); header("Cache-Control: must-revalidate"); $offset = 60 * 60 ; $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; header($ExpStr); ?>
This code will set an expire header for your html page for the amount of 60*60 seconds (1hr). You can adjust the offset to any appropriate amount of seconds.