Prevent caching images

Results 1 to 3 of 3

Thread: Prevent caching images

  1. #1
    Uwe Endres Guest

    Default Prevent caching images

    Hi,<BR><BR>I want to give the opportunity to change the order of images online.<BR>It works, but the images are cached somewhere.<BR>That´s why the page output after the order change isn´t correct.<BR><BR>I am using the following code:<BR><BR>&#060;% Response.CacheControl = "no-cache" %&#062;<BR>&#060;% Response.AddHeader "Pragma", "no-cache" %&#062;<BR>&#060;% Response.Expires = -1 %&#062;<BR><BR>Is there anything I could do to prevent the caching of the images ?

  2. #2
    Ben Timby Guest

    Default RE: Prevent caching images

    The caching may be done by the browser, or a proxy server, the nocache headers work fine for you asp script, but for the images, you will either have to change the names of the images when they are reordered (thus none of them are cached by their old names anymore) or make a script to display an image and call it like so:<BR><BR>&#060;img src="imager.asp?iid=123&rnd=&#060;%=RandomNumber%& #062;<BR><BR>iid should be some unique ID for your image, and random number is just that, and should change between requests. Then you just use the ID to response.redirect them to the image. Using the random number, the image will not be cached. I would suggest just changing the name of the images however, that is probably the easiest method.

  3. #3
    Join Date
    Dec 1969

    Default Good random number

    Using the random number in the url is a good way to prevent getting a cached version. Netscape especially likes to give you cached versions of asp pages.<BR><BR>Generating a truly random number can be difficult however. If the page is hit frequently the client may run into a number they&#039;ve already hit before and get a cached version. For this reason I like to use the current time as my random number. <BR><BR>&#060;img src="imager.asp?iid=123&rnd=&#060;%=Server.URLEnco de(Now)%&#062;<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts