automatic image reload?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JR

    automatic image reload?

    Is there a script available to automatically reload images on visiting
    a page? I change images once a week and they have the same name so
    I'm not changing the page code. Some people have the previous week's
    image in their cache. I'd rather not put a message line on the page
    asking the visitor to hit the refresh button nor use a code that
    reloads the whole page unless reloding the page is an only option.

    Thanks for your suggestions,

    John
  • Lee

    #2
    Re: automatic image reload?

    JR said:[color=blue]
    >
    >Is there a script available to automatically reload images on visiting
    >a page? I change images once a week and they have the same name so
    >I'm not changing the page code. Some people have the previous week's
    >image in their cache. I'd rather not put a message line on the page
    >asking the visitor to hit the refresh button nor use a code that
    >reloads the whole page unless reloding the page is an only option.[/color]

    Append a unique "search" suffix to the src of each image.
    You could do this as the page loads, but it's simpler to
    do it after the load, as in this example:


    <html>
    <head>
    <script type="text/javascript">
    function refreshImages() {
    var search="?"+(new Date()).getTime ();
    for(var i=0;i<document. images.length;d ocument.images[i++].src+=search);
    }
    </script>
    </head>
    <body onload="refresh Images()">
    <img src="http://www.azphx.com/dhtml/tmp/alpha6464.jpg">
    <img src="http://www.azphx.com/dhtml/tmp/beta6464.jpg">
    </body>
    </html>

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: automatic image reload?

      JR wrote:
      [color=blue]
      > Is there a script available to automatically reload images on visiting
      > a page? I change images once a week and they have the same name so
      > I'm not changing the page code.[/color]

      Client-side JavaScript will not help you in general here: It can be
      restricted, disabled or not even supported. You can define that
      standards-compliant UAs should always re-download the document and its
      linked resources from the original source (that should also exclude the
      cache of proxy servers, you did not think about that):

      <head>
      ...
      <meta http-equiv="expires" content="0">
      ...
      </head>

      On the Web (using HTTP,) you can use the `Expires' HTTP header the same way.
      See RFC 2616 for details.

      Another way are cookies that store the date of last visit and if that was
      more than a week ago, you force to reload with `location.reloa d(true)'. But
      their storage may be seen as a violation of privacy.


      PointedEars

      Comment

      Working...