views:

998

answers:

6

In one of My Layout there are some large images (come from XML) which shown when I mouse hover on some some of the link, but when the Page loads and when i rollover It takes time to Load that Image.

Note: there are fix 5 images (not dynamic)

I dont want to use JavaScript to Preload Images any Solutions?

I am Not Using Hover menu or something like that, but this Images are Product Images and the links are Text link Got my Point??

+1  A: 

Reference your images in invisible img tags. while page loading they will downloaded too.

Canavar
+1  A: 

Can't you add them as an <img /> tag to your page and hide them using css?

Peter
+5  A: 

You could use a hidden div to put images in. Like so

<html>
<body>
<div style="width:1px; height:1px; visibility:hidden; overflow:hidden">
    <img src="img1.jpg" /><img src="img2.jpg" />
</div>
<div>Some html</div>
</body>
</html>

This only works for images though, ie. if you're trying to do the same for say .swf files there will be problems. Firefox doesn't run the .swf file if it's not visible.

Matti
Would you also not need display:none since visibility will still take up space? But I also believe that some browsers don't load hidden images till they are shown.
Darryl Hein
This is really Good Solution , we can also Use position absolute and ; height:0 in CSS, Isnt it?
Wazdesign
If it isn't loaded when hidden, maybe it would help have some "visible" span/div of height 0 with style="background:url(imgx.jpg)"? Just an idea... don't know if it helps or works :p
Svish
+21  A: 
Thinker
I can't stress this out enough. This is the (only) way to go.
Kriem
Thanks.. for the Explaination
Wazdesign
+1  A: 

As I'm not sure if hidden images are loaded, you'll probably want to use image sprites. Then the entire image is loaded before anything is displayed. You can even put all of your menu items in one image and therefore save a lot of HTTP requests.

Darryl Hein
+6  A: 

From http://snipplr.com/view/2122/css-image-preloader

A low-tech but useful technique that uses only CSS. After placing the css in your stylesheet, insert this just below the body tag of your page: Whenever the images are referenced throughout your pages they will now be loaded from cache.

#preloadedImages
{
    width: 0px;
    height: 0px;
    display: inline;
    background-image: url(path/to/image1.png);
    background-image: url(path/to/image2.png);
    background-image: url(path/to/image3.png);
    background-image: url(path/to/image4.png);
    background-image: url();

}
Khurram Aziz
Thanks a Lot AZIZ. This is really Good solution for the Preload.Still Hoping for more solutions. Then close the Answer,
Wazdesign