Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got an IIS 7.5 site with caching turned on for javascript and css content directories. All requests to these files use a query string with the app version number, so I just want it to cache forever. But I can't get it to work

In IIS, I've get the caching set up, and I see that the responses for the css files come back with the HTTP Header "Cache-Control: max-age=31536000".

However, the browser keeps requesting the file as I browse pages. The server is responding with 304 - Not Modified which is nice, but I want to avoid the round-trip entirely.

The browser REQUEST keeps including the header "Cache-Control: max-age=0". I don't know if that's a helpful clue or not

share|improve this question
    
Do you have Etag line in header response? You may want to get rid of it as it is the one that most likely forces browser to send those "If not modified" requests (although I do have them enabled myself and I see browser asking for such file once in a while (usually only after initial request) but not constantly for sure). BTW -- how do you check the headers (that file is cached) -- I hope not by hitting <kbd>F5</kbd> in your browser? If you can -- can you post a link to such site/file? –  LazyOne Jul 5 '11 at 17:15
    
Check your expires header - if it is set and contains any error that value will over-ride your max-age. You may also want to add 'public' to your Cache-control line –  cyberx86 Jul 5 '11 at 17:17
    
I'm checking the caching just by browsing the site and watching in fiddler or Chrome's network tab. The server is not sending a Expires header, but it is sending an ETag header. I'll try removing that. –  Clyde Jul 5 '11 at 17:21
    
@Clyde This is the header that I have: Cache-Control: max-age=31622400,public ; I do have Etag and I do not have Expires header .. but I still have all of my static resources cached (lucky me?). Please also do what @cyberx86 suggested: add to web.config: <system.webServer><httpProtocol><customHeaders><add name="Cache-Control" value="public" /></customHeaders></httpProtocol></system.webServer> –  LazyOne Jul 5 '11 at 17:39
    
OK, I got the answer -- it's a developer issue not an IIS issue so my whole question is a bit of a red herring. There are some javascript location.reload(true) in the code which are forcing re-requests of the data. –  Clyde Jul 5 '11 at 17:53

1 Answer 1

I thought about deleting the question, but then decided to put my resolution out here in case it might be helpful to someone. To copy from my comment: it's a developer issue not an IIS issue so my whole question is a bit of a red herring. There are some javascript location.reload(true) in the code which are forcing re-requests of the data.

share|improve this answer
    
That's a good decision -- never knows where the trouble may be. –  LazyOne Jul 5 '11 at 18:10

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.