Using an image preloader script in your template.

Written by on November 9, 2009 in Development tips - 5 Comments

If you are using mouseover images for your navigation and want to prevent the lag time of the images loading before you can mouseover, then using a image “preloader” script is the way to go.

Add the following Javascript snippet just above your closing head tag:

<html>
<head>
<script type="text/javascript">
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</script>
</head>

Then add the full url’s of the images you want to preload in the body tag.

About the Author

Matthew King is the excessively caffeinated head of customer service and system administrator for JoomlaJunkie. He loves paintball and dry humor. Matt also sells web hosting and does website design at ColumbusGEEK.com. He is based in Columbus, Ohio (USA).

5 Comments on "Using an image preloader script in your template."

  1. Igor December 6, 2009 at 4:26 pm · Reply

    Hello, is it possible to preview the templates before installing them in Joomla (it’s zip file, so I don’t think so).
    It’s easier to download a lot of templates at once from web but installing them one by one is time consuming. Is it possible to copy/paste them in template file like pictures and in that way avoiding entering them one by one, or preview them in some way.

    Thanks and all the best

  2. matt December 7, 2009 at 4:44 pm · Reply

    I think you would be hard presssed to find a web template company that did not have a preview and a demo of their goods.

  3. Franklin June 11, 2010 at 8:31 pm · Reply

    hello matt, im new to joomla and I found it interesting. But there are some issues I want to know more like how can I make my website load faster. and specially the images. is there any image preloader for images? why joomla site load very slow? how can I speed it up?

  4. Franklin June 11, 2010 at 8:33 pm · Reply

    does the pre-loader code you have above apply to any image?

    thanks
    .-= Franklin´s last blog ..It’s Gonna Make Sense =-.

  5. Lisa July 10, 2011 at 10:59 pm · Reply

    So can you give me an example of what the body tag would look like with the image url’s. I’m trying to make it work and it’s not working properly. Thanks!

Leave a Comment