3

I have a wcf service serving images, these images are volatile and regularly updated. I display them on a webpage using an img tag

<img src="location/map/image/{coordinates} 

cordinates is a number e.g. 12786. In my javascript I create and remove the image tag at different times. I have used the following code to add HTTP headers to prevent caching

    //whatever the result we will not cache this at the client or intermediate proxies
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
    HttpContext.Current.Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
    HttpContext.Current.Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
    HttpContext.Current.Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
    HttpContext.Current.Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1 
    HttpContext.Current.Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1 
    //write the image http response

I have noticed that in firefox the image is never refeshed and resorted to adding a dummy query string parameter. I have come to understand that firefox DOM will notice that the image url has been used before on the same page and won't refresh it.

This seems to be completely against Http(REST) since the image is not linked to the document in anyway and is a seperate HTTP resource why should it's accessibility be determined by the page/DOM it is referrenced in.

This is completely against HTTP.

My question is; is there a way of preventing this behaviour in firefox using HTTP? Please don't say Response.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); it doesn't work on FF.

I am using FF6.

smoothe
  • 568
  • 1
  • 4
  • 11
  • This may help you: http://stackoverflow.com/questions/5063338/prevent-scripts-from-being-cached-programmatically – Al Kepp Oct 14 '11 at 00:16
  • using a handler is much the same as using a service cos I can do all the same things in both so the above won't solve my issue at all. – smoothe Oct 14 '11 at 00:23

2 Answers2

1

Try adding the following:

HttpContext.Current.Response.AppendHeader("Pragma", "no-cache"); 
HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache");

HttpContext.Current.Response.CacheControl = "no-cache"; 
HttpContext.Current.Response.Expires = -1;

HttpContext.Current.response.ExpiresAbsolute = new DateTime(1900, 1, 1); 
HttpContext.Current.response.Cache.SetCacheability(HttpCacheability.NoCache);
sarnold
  • 102,305
  • 22
  • 181
  • 238
RBZ
  • 2,034
  • 17
  • 34
  • Works on IE, Chrome but not FF – smoothe Oct 14 '11 at 00:26
  • Then there is no way that setting variables on the server is going to work. If FF won't play fair then I would append the current timestamp to the request. (but as I recall I had this problem in IE7) – RBZ Oct 14 '11 at 02:07
0

Ok I need to close this and the result is FF needs to be fixed, I will add a bug on the FF website.

Thanks to everyone who answered and looked at this question hopefully this will help some googler in future.

smoothe
  • 568
  • 1
  • 4
  • 11