Image Preloader - Description

  1. Add the following code to the document you want to use the script in:

    
    <script type="text/javascript" src="image_preloader.js"></script>
                      

    If the image_preloader.js file is in a different directory than the html document, be sure to include the relative path to the Javascript file in the src attribute value.

  2. Add an onload event handler to your <body> tag that reads onload="preloadImages();". If your <body> tag already has an onload event handler, append preloadImages(); to the current value (be sure to add a ; to the end of the current value if there isn't one already).

  3. Between the parentheses in the event handler, add the names of the image files as a quoted, comma-separated list. The file names must be valid relative or full urls. For instance, if you wish to preload two images called sample1.gif and sample2.gif both of which are in a directory named images, the event handler should read:

    
    onload="preloadImages('images/sample1.gif', 'images/sample2.gif');"
                      
  4. Have a nice day.

More about this script

Related to this script

Licensing

This script is released under a Creative Commons License.