views:

100

answers:

4

I'm serving up some files via an HTTPModule in asp.net. I want to know if there are any benefits to setting, or not setting, the Cache-Control header to something (like no-cache)?

Edit: The reason I'm curious about this is because we ran in to a problem where serving up office documents over an SSL session in IE results in an error (with Cache Control set to no-cache). That is to say, you cannot download office docs over SSL in IE if you have set Cache-Control to no-cache.

Basically I want to NOT include the Cache-Control header, but wonder if it will cause problems?

Edit 2: Well, the Cache-Control header is out. I tried the suggestions below but had some problems. Any time I add an expires header, or change Cache-Control at all, when I try and open an Office 2007 document it tries to open it as a zip. (I know that they're really zip files under the covers) but when I don't use an expires header or cache-control IE opens them just fine as Office Documents. Unfortunately I don't have time to try and figure all this out - as code freeze is ten minutes from now :)

Thanks everyone for trying to help!

+2  A: 

According to Yahoo! and YSlow you should. See this article.

Update: Based on your comment it looks like you are trying to prevent caching. I would use:

Cache-Control: max-age=0 

To me, it's simpler and more explicit than using an Expires header.

Update 2: Sounds like you need to specify the Content-Type header for the office documents. Try using below:

Content-Type: application/octet-stream
Taylor Leese
I assume no-cache is what they think I should set it to? The problem with no-cache is that if you're running over an SSL session, you cannot download Office documents in IE. I want to remove the no-cache cache control header, but I'm worried about getting stale documents.
Eric
I updated my answer for you.
Taylor Leese
You might find this SO question interesting: http://stackoverflow.com/questions/1046966/whats-the-difference-between-cache-control-max-age0-and-no-cache
Taylor Leese
Thank you very much for the suggestion! Unfortunately as I mentioned in my edited question above - now instead of recognizing Word 2007 documents as Office file formats, IE tries to open the file as a zip. When I remove the Cache-Control header completely IE 8 again knows that the files are Office docs. Strange!
Eric
Set the Content-Type header to application/octet-stream for the office documents.
Taylor Leese
Thanks Taylor, I think the Content-Type is already octet-stream, but I'll double check!
Eric
I guess I wasn't setting the content type header! I thought for sure I was, but when I check in firebug it's not being sent in the response. Thanks!
Eric
+1  A: 

Instead of using Cache-Control you could try to set the Expires header to a past date/time.

Josh Stodola
Will most modern browsers and proxies honor the expires header? It's been too long since I've actually known what parts of HTTP 1.1 are fully supported and which ones are still iffy.
Eric
In terms of HTTP proxies I know Squid can handle Cache-Control and Expires.
Taylor Leese
See my edit above - I tried the expires header but IE 8 was opening the office documents as zip files. Without the expires header IE knows to open the office docs in Office. Strange I know... but I don't have time to figure it out :( Thanks for the suggestion though!
Eric
Did you specify a content-type header? That's an important one.
Josh Stodola
Yeah, application/octet-stream should probably do the trick.
Taylor Leese
+1  A: 

That is definitely an odd issue... but here is quick solution that could prevent your users from getting stale content:

If you append an additional querystring parameter to the end of your URL to make each request for the Office file unique, you can get away without setting the cache-control information in the header.

Your current URL may look like this:

http://mysite.com/filegetter?name=document.doc

With the additional "unique" parameter:

http://mysite.com/filegetter?name=document.doc&ts=

This will prevent the browser from giving your user a stale office file, and the method could be implemented in client or server code. The module that handles shipping the file back to your users simply ignores the portion of the URL that makes it unique to your user's browser.

smencer
This is true and should work, but it's a little hackish. I believe Cache-Control: max-age=0 should do the same thing.
Taylor Leese
No doubt, it is "workaround"... but it will work. I think this is the method that YUI uses to ensure AJAX requests aren't cached by the browser.
smencer
I actually like this method of keeping files fresh. It works great with css files and js files. ASP.Net uses this when making requests to the WebResource.axd handler. Unfortunately this is not an option for me, as there are way too many links out there without this query string parm, and I only have a matter of minutes to make the fix :(
Eric
A: 

I had to use "no-store" to successfully render PDF files inside IE6 with no caching.

lance
Thanks for the great idea in the post you linked to. I was hopeful! I tried it and the office documents open fine. Unfortunately IE 8 is still caching images that are served up via this same HTTPModule. That is to say, I'm not sure it's really doing anything to prevent stale documents. (docx, pdf etc were never really a problem in terms of caching, but images served up via this same module are :( I will probably have to handle the images as a separate case.)
Eric