Preloading images in HTML, is there a more modern way?
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-05-26T09:29:51Z
Indexed on
2010/05/26
9:31 UTC
Read the original article
Hit count: 189
JavaScript
|html
I have an image loaded by JS on a mouse event. It's a fairly big image so I want to make sure it gets pre-loaded. I reemmber some old techniques from years ago and found this example:
<SCRIPT LANGUAGE = JAVASCRIPT>
if (document.images)
{
img1 = new Image();
img2 = new Image();
img1.src = "imageName1.gif";
img2.src = "imageName2.gif"
}
</SCRIPT>
I wondered if this is still good/relevant, or maybe browsers automatically detect unused images and preload them anyway? Note my page has to support IE6, so I might still need older techniques anyway, but I'm still interested if more modern browsers have a better way?
© Stack Overflow or respective owner