Share via


Suppress caching of certain MIME types like GIF, JPG etc

I had an interesting problem sometime back which I would like to share.

We had a page which did some data processing and created a graph (in GIF format) based on that page's information. The GIF file got overwritten (new graph got generated due to the change in values in my form) everytime I clicked on the submit button, but the output simply won't reflect in the browser on the postback. BUT, If I did CTRL + F5, it got me the latest file from the server and this time I could see the updated graph.

If we change the IE setting from "Tools -> Internet Options -> Settings -> Automatically" to "Tools -> Internet Options -> Temporary Internet Files Section -> Settings -> Every visit to the page", the problem goes away.

The issue isolated to the fact that the IE was caching the GIF files. The *BIG* question is how do you fix it from the Server side so that clients don't have to re-adjust their IE settings. One option was ASP.NET caching, but it won't work with the GIF or other static files. META cache also didn't work. So, here is what you need to do...

We added the Headers to the gif files and now everything works fine. Here is what we did to resolve it.

»»» Click on "Start -> Run" and type inetmgr and click Ok
»»» Navigate to /FolderName (folder where you have those gif files).
»»» Right click on that Folder and click Properties
»»» Click on HTTP Headers tab
»»» In the Custom HTTP Headers frame, click on Add button
»»» In the Custom Header Name, type "Cache-Control" without quotes
»»» In the Custom Header Value, type "no-cache" without quotes
»»» Click on Ok twice
»»» Click on "Start -> Run" and type iisreset and click Ok
»»» That fixes the issue!!

The GIF files are no longer cached on the client now, because of the Header information sent from the IIS and the they get refreshed regardless of the IE setting solving our issue :o)

Comments

  • Anonymous
    August 04, 2006
    bhadia hai bedu. Simply great.
    But tell me how this solution works internally. Like how IE reads the header and what makes it not to chache the gif files.
  • Anonymous
    August 06, 2006
    Actually, you might like to try http://www.fiddlertool.com/fiddler/

    Using this tool, you will get to know how things look pretty to the eyes, where looking at things "raw" has a completely different picture to it.

    Check it out and see the difference in the tool with and without the settings as per the entry!