Wednesday, November 9

Avoiding images being cached

I saw a question on the Developer Fusion web site today.

This reminded me of a problem we had, where we had image files that were generated from a database, containing graphs of web site usage.

We found the images were frequently cached, and old graphs were shown to our users. To resolve this, we added a QueryString containing a random number after the image file name in the HTML, using simple C# code as follows:

<% System.Random r = new System.Random(); %>
<img src=myimage.gif?<%Response.Write(r.NextDouble()); %>>

No comments: