Should I set the Cache-Control header when serving files? Or not?

I serve some files through the HTTPModule in asp.net. I want to know if there are any advantages in setting or not setting the Cache-Control header on something (for example, without a cache)?

Edit: The reason I am interested in this is because we ran into a problem when servicing office documents through an SSL session in IE results in an error (Cache Control is not installed with -cache). That is, you cannot download office documents via SSL in IE if you installed Cache-Control in no-cache.

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

Edit 2: Well, the Cache-Control header is missing. I tried the suggestions below, but had some problems. Each time I add the expires header or even modify Cache-Control when I try to open an Office 2007 document, it tries to open it as a zip. (I know that they really are zip files under covers), but when I don't use the expires header or cache control, IE opens them just fine, like Office documents. Unfortunately, I don’t have time to try to understand all this - since the code freezes for ten minutes :)

Thank you all for your help!

+6
c # download
source share
4 answers

According to Yahoo! and YSlow you need. See Article.

Refresh . Based on your comment, it looks like you're trying to prevent caching. I would use:

Cache-Control: max-age=0 

For me, this is simpler and more explicit than using the Expires header.

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

 Content-Type: application/octet-stream 
+2
source share

Instead of using Cache-Control you can try setting the Expires header to the past date / time.

+1
source share

This is definitely a weird problem ... but here is a quick fix that might prevent your users from receiving outdated content:

If you add the optional querystring parameter at the end of your URL to make each request for the Office file unique, you can leave without setting cache management information in the header.

Your current url might look like this:

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

With an additional "unique" parameter:

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

This will not allow the browser to provide your user with an outdated office file, and this method can be implemented in the client or server code. The module that handles sending the file back to your users simply ignores the part of the URL that makes it unique to your user browser.

+1
source share
0
source share

All Articles