Prevent Caching Using .htaccess

Discussion in 'Apache' started by AHA7, Aug 11, 2008.

  1. #1
    Hello,

    Is there a way to include a no-cache header for all .css files using .htaccess?

    I don't want my .css files to be cacheable.
     
    AHA7, Aug 11, 2008 IP
  2. AHA7

    AHA7 Peon

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just found this code:

    <FilesMatch "\.(html|htm|js|css)$">
    FileETag None
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </FilesMatch>
    Code (markup):
    I have mod_rewrite rules in my .htaccess so should this go above or below those rules?

    Also what does FileETag None & Header unset ETag mean?
     
    AHA7, Aug 11, 2008 IP
  3. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #3
    The FileETag directive configures the file attributes that are used to create the ETag (entity tag) response header field when the document is based on a file. (The ETag value is used in cache management to save network bandwidth.) In Apache 1.3.22 and earlier, the ETag value was always formed from the file's inode, size, and last-modified time (mtime). The FileETag directive allows you to choose which of these -- if any -- should be used.
    None
    If a document is file-based, no ETag field will be included in the response

    more about FileETag: http://httpd.apache.org/docs/2.2/mod/core.html

    An ETag (entity tag) is an HTTP response header returned by an HTTP/1.1 compliant web server used to determine change in content at a given URL. When a new HTTP response contains the same ETag as an older HTTP response, the contents are determined to be the same without further downloading. The header is useful for intermediary devices that perform caching, as well as client web browsers that cache results. One method of generating the ETag is based on the last modified time of the file and the size of the file.
    more about ETag: http://en.wikipedia.org/wiki/HTTP_ETag



    have you tested that code? does it work fine?
     
    pr0t0n, Aug 11, 2008 IP
  4. AHA7

    AHA7 Peon

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the info!

    I haven't tested it yet and I am trying to make it as simple as possible. Will the following code be sufficient to prevent caching?

     
    AHA7, Aug 11, 2008 IP