1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Avoiding loading image from cache?

Discussion in 'Software' started by Dad, 14 Oct 2005.

  1. Dad

    Dad You talkin to me?

    Joined:
    15 Apr 2003
    Posts:
    5,375
    Likes Received:
    8
    On part of my new Intranet for work, I'm pulling images down from a remote server so people who don't have Internet access can view them (with permission of course ;)). This is working perfectly fine, however the image changes every 10 minutes (filename remains constant). The problem is that if there is an image with the same filename that is stored within the user's cache, the browser will load the image from cache instead of the new one. Is there a way to force the browser to ignore the cache and pull the new image? Javascript is fine, asp is prefered.
     
  2. John Cena

    John Cena What's a Dremel?

    Joined:
    1 Jun 2004
    Posts:
    818
    Likes Received:
    0
    Use this

    If the page name is default.html

    Use this

    http://www.lol.com/default.html?

    That should bring a new page everytime.

    If it an ASP page, just set the response encoding level.
     
  3. Dad

    Dad You talkin to me?

    Joined:
    15 Apr 2003
    Posts:
    5,375
    Likes Received:
    8
    I thought of that, but it doesn't work with images. The page may be reloaded, but the images are being pulled from cache. I've also tried:

    <%
    Response.CacheControl = "no-cache"
    Response.AddHeader "Pragma", "no-cache"
    Response.Expires = -1
    %>

    and changing the content expiration on the web site properties within IIS to expire immediately with no joy.
     
  4. Dad

    Dad You talkin to me?

    Joined:
    15 Apr 2003
    Posts:
    5,375
    Likes Received:
    8
    figured it out after losing a few clumps of hair. I was thinking about that question mark thing and tried something simple as follows:

    <img src="/cache/weather/radar.jpg?<%=left((replace((time()), ":", "")), 6)%>">

    I figured that the since it's an image, the browser would ignore the ? and everything after it as far as displaying goes. Now, when the browser loads the image, it caches it as radar.jpg? and then it will put in the modified time - ie: radar.jpg?120543. That way eventhough it may be cached, it will pull the image from the server as it's not quite the same name. I just hope it downgrades to lower versions of IE.. Time will tell...
     
  5. Hepath

    Hepath Minimodder

    Joined:
    20 Oct 2003
    Posts:
    730
    Likes Received:
    0
    Looks like you've stumbled onto the answer I would have given :)

    The answer should be backwards compatable as images are referenced throught HTTP .. which (for IIS) can effectively distinguish an image from a page and ignore what in effect is a query string.
     
  6. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    that's how my webcam page is served, so, as for hepath, that's the answer I woulda given too.
     

Share This Page