Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    281
    Thanks
    2
    Thanked 0 Times in 0 Posts

    prevent loading of cached image

    Is there some way that I can not load one image from the cache? It is replaced all of the time, and needs to not load from the cache.

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont know if this will apply to images aswell but you could try:

    <meta http-equiv="pragma" content="no-cache" />

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    281
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Doesn't that code prevent things from going into the cache? I want pages and images to be cached. On a certain page, I want the image that is loaded to not load from the cache. Does that make sense?

    It's not that I want an image to be prevented from being cached, I just don't want it to be loaded from that cache when it is referenced in a particular page.

  • #4
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you have any form of server-side access. Im not sure about ways to specificly say what can be loaded from the cache and what not, but If you could access PHP you could use something like:

    Code:
    <a href="image.php" alt="Blah" />
    then have:

    PHP Code:
    header("Content-Type: image/jpeg");
    readfile("image.jpg"); 
    which should in theory reload the image every time

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If your page is coming from a server side script (PHP or otherwise) you can use this simple technique:

    <img src="myimage.png?insert datetime stamp here" alt="Some text" />

    Use whatever function in your server side script that'll put the current date and time into that space after the ?.


    Please note that missing-score meant use: <img src="image.php" alt="Blah" /> and accidently wrote an <a> tag instead.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeh sorry about that

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    281
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yes, I am using php...so that will hopefully work! Thank you very much!

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is a javascript solution which is much like Roy's suggestion in that it adds the UTC Time to a querry at the end of the image URL. If you check your TIP files you will find a different image cached eac time the page is called.
    Code:
    <script type="text/javascript">
    <!--//
     var myImage = new Image()	
     myImage.src = 'http://www.stadiumsofnfl.com/afc/aldelph102.jpg?';
      function chkCache() {
        var clocktime = new Date();
        var utchours = clocktime.getUTCHours();
        var utcminutes = clocktime.getUTCMinutes();
        var utcseconds = clocktime.getUTCSeconds();
        var utcyear = clocktime.getUTCFullYear();
        var utcmonth = clocktime.getUTCMonth()+1;
        var utcday = clocktime.getUTCDate();
        var utctime = utcyear + utcmonth + utcday;
            utctime += utchours + utcminutes + utcseconds;
     
          isNew = myImage.src;
            if(!isNew.match('#')) {
               document.images['noCache'].src = myImage.src+utctime;
            }
          else{document.images['noCache'].src = document.images['noCache'].src;
        }
      }
     //-->
    </script>
    </HEAD>
    
    <BODY onload="chkCache()">
    <img name="noCache" src="http://www.stadiumsofnfl.com/afc/aldelph102.jpg" width="640" height="480" alt="Adelphia Coliseum">
    </CENTER>
    </BODY>
    </HTML>
    .....Willy

  • #9
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The php solution may be a better idea as people may have javascript disabled although both should work fine.

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you go with the PHP solution, make your image script as specified. If you decide to write a "generic" script which can be used to pick off any image using a parameter passed on the URL (<img src="image.php?actualimagename.jpg" alt="Hah" />) you must also add code to the PHP script to validate the image name returned, otherwise you've opened a hole for hacking into your site and the hackers may do something like this: <img src="image.php?image.php" alt="Gotcha" /> and be able to read your scripts merely by looking in their cache.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    281
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I went with your original post, Roy, and it works great. Thanks.


  •  

    Posting Permissions

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