How to set the cache-control sent to a user’s browser?

Quick guide on how to change the headers sent to the browser

You can use an .htaccess file in your public_html folder to control the cache headers sent to the browser.

For example, this can be used to control what should not be cached in your visitors’ web browser.

Please see the following article for additional information to learn how to prevent the caching of particular filenames using an .htaccess file: http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html#prevent-caching-with-htaccess

Posted 2008-05-02 in Linux Web Hosting    Popularity: 34%

Comments

  • An updated cache-control article is also helpful.

    Here’s what my site is using, it seems simple but alot is going on.

    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>

    Author: AskApache    Posted: May 2nd, 2008 at 10:42pm

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>