#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0

    No cache only one .gif file


    Hi, I need to block a .gif file for being cached, for a technical reason until hopefully fixed.
    I dont want to put no cache on all .gif files, so is there a way to add a no cache to only one .gif file?

    Ah, and if possible, I only want no cache for that file for my dear browswer ie....
    Thanks in advance
    Last edited by helenp; November 15th, 2011 at 05:30 AM.
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,127
    Rep Power
    4304
    Here's how to disable caching for a single file. FilesMatch accepts a regular expression though (which is why the backslash is before the "."), so you can also use this to match multiple files.
    Code:
    <FilesMatch "filename\.gif">
      Header set Pragma "no-cache"
      Header set Cache-Control "no-cache, must-revalidate"
      Header set Expires "Thu, 01 Dec 1994 16:00:00 GMT"
    </FilesMatch>
    As far as doing a user-agent (e.g. browser) match... it's often misused, so I don't want to post how to do it publicly.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    Originally Posted by Kravvitz
    Here's how to disable caching for a single file. FilesMatch accepts a regular expression though (which is why the backslash is before the "."), so you can also use this to match multiple files.
    Code:
    <FilesMatch "filename\.gif">
      Header set Pragma "no-cache"
      Header set Cache-Control "no-cache, must-revalidate"
      Header set Expires "Thu, 01 Dec 1994 16:00:00 GMT"
    </FilesMatch>
    As far as doing a user-agent (e.g. browser) match... it's often misused, so I don't want to post how to do it publicly.
    Thanks but dont know what I am doing wrong as I dont make it to work.
    The javascript is in a folder and the gif is as well,
    this is how it should be for me, but nothing works:
    <FilesMatch "images/ajax-loader\.gif">
    Header set Pragma "no-cache"
    Header set Cache-Control "no-cache, must-revalidate"
    Header set Expires "Thu, 01 Dec 1994 16:00:00 GMT"
    </FilesMatch>
    <FilesMatch "\.(gif|jpeg|jgz|gz|jpg|js|pdf|css|png|flv|swf|ico)$">
    Header set Cache-Control: "max-age=29030400"
    </FilesMatch>
    Thanks,
    Helen
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,127
    Rep Power
    4304
    1) You need to reverse the order of the <FilesMatch> directives. More specific ones need to come after general ones.

    2) You can't specify a directory with FilesMatch. If you want to restrict the match to that directory, you'll need to make another .htaccess file for that <FilesMatch> directive and put the new .htaccess file in that directory.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    Originally Posted by Kravvitz
    1) You need to reverse the order of the <FilesMatch> directives. More specific ones need to come after general ones.

    2) You can't specify a directory with FilesMatch. If you want to restrict the match to that directory, you'll need to make another .htaccess file for that <FilesMatch> directive and put the new .htaccess file in that directory.
    Thanks, I only need to restrict one file however I use it from several directories.
    I added this at the end of all filesmatches:
    <FilesMatch "ajax-loader\.gif">
    Header set Pragma "no-cache"
    Header set Cache-Control "no-cache, must-revalidate"
    Header set Expires "Thu, 01 Dec 1994 16:00:00 GMT"
    </FilesMatch>
    And it worked....without any directory name and in all folders that uses it. Thanks a lot.

    Edited: lol, all directories uses the same .jsfile....
    Helen
    Last edited by helenp; November 15th, 2011 at 11:45 AM.

IMN logo majestic logo threadwatch logo seochat tools logo