Skip To Main Content | Home | Sitemap | Contact
Latest Visitors: United States's flagUnited States's flagUnited States's flagUnited States's flagGermany's flagUnited States's flagSweden's flagMalaysia's flagMalaysia's flagUnited States's flagIsrael's flagUnited States's flagChina's flagChina's flagSweden's flagIndia's flagAustralia's flagIndonesia's flagNorway's flagVietnam's flagTurkey's flagGermany's flagGermany's flagUnited Arab Emirates's flagIndia's flag
 

How can you load an external image without loading the cached copy from the browser?

Update 2009-12-18:

This loads images to an existing (already loaded) page using the method discusses in the Remote Scripting Images tutorial.

A new image is created using the document.createElement() method.  The new image element is set to the remote image source, then when that image reports that it has loaded, the existing image element is replaced with the new image element.

Because the image is loaded remotely and not placed in the page until after it loads, there is no top to bottom rendering, as you might see when a page loads an image directly.  A simple timer is used to load the different images.

This example page will stop after 15 image loads and not restart. This is to save bandwidth. Some people have let this run endlessly, polluting my web server logs with hundreds of entries.

my son fishing


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">

<head>
<title>Reading Images From The Server With No Preload And No Retrieving From The Browser Cache.</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="en-US">
<meta name="author" content="Roderick Divilbiss">
<meta name="copyright" content="© 2005-2010 Roderick Divilbiss">
<script type="text/javascript">
/*******************************************************************
 *  The Remote Image Loader
 *******************************************************************/
function getImage(pExistingImageID, pImageURL){
    var img = document.createElement('img');
    img.onload = function (evt) {
        document.getElementById(pExistingImageID).src=this.src;
        document.getElementById(pExistingImageID).width=this.width;
        document.getElementById(pExistingImageID).height=this.height;
    }
    img.src = pImageURL;
    return false;
}

var currentImage = 1;

function rotateImage() {
    var iSrc = '/asp/images/image' + currentImage + '.jpg';
    getImage('mainImage',iSrc);
    currentImage += 1;
    if (currentImage==4) {
        currentImage=1;
    }
    setTimeout('rotateImage();',2000);
}
</script>
</head>
<body onload="rotateImage();">
<p><img id="mainImage" border="0" src="images/image1.jpg" width="300" height="250"></p>
</body>

</html>


This Weeks Most Popular Pages Newest Pages