There are many instances though where we know in advance that we want to update the page to display certsin images (or at least that they are likely to be required). Where we know that an image will be required later we can actually use JavaScript to request it to be downloaded in advance without the downloaded image being added to the page straight away.
In this example we request for all four season images to be downloaded into the browser cache even though only one of them is displayed in the page. This will allow us to add further code to the page (not shown) that then cycles through all the images without any delay the first time each image is requested (assuming that sufficient time elapses to download the images prior to our requesting them). Even if an image is still being downloaded when the additional code to add it into the web page is called it will still update faster than if we don't use the preload code because the image will at least have already started downloading in advance.
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Example D13</title>
</head>
<body>
<img id="season" src="summer.gif" alt="season">
<script type="text/javascript" src="exampleD13.js"></script>
</body>
</html>
JavaScript
var backImg, img;
backImg = ['summer.gif','autumn.gif','winter.gif','spring.gif'];
img = []; for (var i = backImg.length; i >= 0; i--) {
img[i] = new Image();
img[i].src = backImg[i];
}