Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am using IIS7, I have already set up the following. But when I run Firefox it seems not to cache any of my images even with "remember history" set.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>

However when I use Firebug it still points to Firefox not caching images and CSS:

public,max-age=604800
Content-Type    text/css
Content-Encoding    gzip
Last-Modified   Mon, 27 Jun 2011 03:53:22 GMT
Accept-Ranges   bytes
Etag    "507968c27d34cc1:0"
Vary    Accept-Encoding
Server  Microsoft-IIS/7.5
X-Powered-By    ASP.NET
Date    Mon, 27 Jun 2011 13:06:41 GMT
Content-Length  5067
Request Headersview source
Host    www.xx.com
User-Agent  Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept  text/css,*/*;q=0.1
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://www.xx.com/
Cookie  __utma=62996397.135679654.1309106351.1309159743.1309164158.8; __utmz=62996397.1309106351.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmc=62996397
share|improve this question
add comment

3 Answers

What is the request URI for the CSS file? Firefox will not cache the result when the URI contains a query string (i.e. a ? followed by parameters).

According to the HTTP specifications, a browser should never cache a response from a request containing a query string unless the server explicitly allows it. Unfortunately though, Firefox and IE do not comply to this rule. IE does cache it regardless of a query string but Firefox never caches it regardless of any cache control headers.

share|improve this answer
    
This answer is outdated. The current versions of Firefox, Chrome and IE11 all cache resources with a query string, at least when served with a "Cache-Control: max-age=12345" header. –  romkyns Feb 28 at 16:53
    
So @romkyns, this mean that these browsers now comply to the specifications. Thanks for the update. –  Marco Miltenburg Mar 3 at 21:52
add comment
  1. Remove the etag header

  2. Use the Cache-Control header to have a large max-age value

  3. Set the Expires header to be a far future date

I am unsure how to do this with IIS but if you do the above Firefox should cache your images and any other files you wish to have cached.

share|improve this answer
2  
If the same resource is only served from single server (no CDN) then having etag does not hurt. In IIS6 etag was changing after each configuration alteration. In IIS7 this is no longer an issue. I have etag on all such servers and all browser caching images/css/js with no problems. –  LazyOne Jun 27 '11 at 13:55
    
Hello Jon, I thought the whole idea of setting max-age was that I would not have to set an expires date? I have the max-age set at 7 days. Surely firefox would cache if it saw something was going to be of use for the next 7 days. How do I remove the etag header. Maybe that's what's causing my problem. Can I do that on a per-directory basis? –  Richard A Jun 27 '11 at 13:55
    
It's from a single server IIS7 (Windows Azure). –  Richard A Jun 27 '11 at 13:56
1  
@Richard A, I use Apache on Linux so I am unfamiliar with how this is done on IIS. But I use a far future date for cache-control and expires and have unset etag since I've read that it isn't very good and also unnecessary if you use the two methods above. I find this is an effective means for caching in every browser including Firefox which is the browser I do most of my testing on. –  John Conde Jun 27 '11 at 14:00
    
@Richard You better ensure that caching is working for images first. –  LazyOne Jun 27 '11 at 14:16
add comment
  1. Have you enabled static content compression in IIS?

  2. Apparently (according to this question: http://stackoverflow.com/questions/6420995/iis-7-x-static-compression-not-frequently-hit) IIS may decide not to compress files if they are RARELY accessed. I have not had ANY issues with this point -- even freshly created file worked fine.

  3. Use bigger max-age value -- 30 days or more (although it should not affect caching THAT much to completely prevent file from being cached).

share|improve this answer
    
I'm setting my cache for 7 days ahead but it doesn't seem to work for even 7 seconds :-( How do I enable static content compression? –  Richard A Jun 27 '11 at 13:53
    
<system.webServer><urlCompression doStaticCompression="true" /></system.webServer> –  LazyOne Jun 27 '11 at 13:59
    
TBH "static content compression" should not affect caching, but some times it does (don't ask why -- I cannot explain). I just having it On for js/css and other static files -- it does the job well. –  LazyOne Jun 27 '11 at 14:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.