Javascripters: What does this do?

(This is for a webcam)
Does this reload the image when the image is new or does it reload it at a specific interval, or what? I know it sounds like a dumb question but I can’t tell:
<img src=“current.jpg” name=“refresh” width=“306” height=“408”>
<script language=“JavaScript” type=“text/javascript”>
<!–
image = “current.jpg” //name of the image
function Reload() {
tmp = new Date();
tmp = “?”+tmp.getTime()
document.images[“refresh”].src = image+tmp
setTimeout(“Reload()”,1000)
}
Reload();

  // --&gt; 
  &lt;/script&gt;

It refreshes every 1000 miliseconds. It also gives the image object a new random source to avoid caching.

The database took a dump before I could edit and expound…

It gets the current date/time so that it can make a string out of the time and the string is unique enough to slap on to the end of the image file name to make it seem new.

So every 1000 miliseconds it is changing yourimage.jpg?12345 to yourimage.jpg?12346 and that’s enough to make your browser think that yourimage.jpg is new and doesn’t cache it.

Aha! Thanks!

One extra bit: yourimage.jpg?12345 and yourimage.jpg?12346 are the exact same file. The part after the question mark is the argument for the file, but since an image doesn’t accept arguments (by default), it is ignored on the server. It is not ignored by your web browser, however, and that’s why it accomplishes what ZipperJJ states.

I personally wish there was just a “nocache” argument that could be sent to images. It could even be a CSS property. These JS workarounds are ugly, in my opinion.

What is the purpose of preventing caching of an unchanging image?

Given the fact that the name of the image is “current.jpg”, I don’t think your assumption of it not changing is valid. My guess they have some back-end process that writes a new image file periodically for some reason. If user’s browsers are caching the image, they won’t see the latest version.

This would be a technique that could be utilzed in remote monitoring software, stats, etc - I’ve seen it before for website statistics.

It is for a webcam. So the image is new every few seconds when the cam is on - hence not wanting to cache it.