Results 1 to 4 of 4

Thread: Preload images that don't exits

  1. #1
    Join Date
    Dec 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Preload images that don't exits

    Hi

    I'm using this code to preload images in my e-commerce website. Can't remember where I got the script but it works.

    <SCRIPT LANGUAGE="JavaScript">

    var aryImages = new Array();

    aryImages[0] = "prod_1_A.jpg";
    aryImages[1] = "prod_1_B.jpg";
    aryImages[2] = "prod_1_C.jpg";
    aryImages[3] = "prod_1_D.jpg";

    for (i=0; i < aryImages.length; i++) {
    var preload = new Image();
    preload.src = aryImages[i];
    }

    </script>

    I have around 600 products on my site, some have 2 images, some 4 images etc and would like to have one script that does all instead of 600 slightly different scripts.

    So, the question is, what happens if I add two more images, prod_1_E & prod_1_F, to the array even tho they don't exist?

    I've tried it and it seems to work. Just wanted to know if it's OK or will I hit probs further down the line.

    Cheers

    Ian

  2. #2
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    No matter how it may seem, that code does not work because it doesn't use a non-volatile array. It will only pre-load the last specified image.

    You don't actually need JS to pre-load, but if you're using it anyway you can try this pre-loader:

    http://scripterlative.com?preloader

  3. #3
    Join Date
    Dec 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi

    Thanks for the reply. I'm using the scripterlative Thumbsmart script and the reason for the pre loading is that the main large image sometimes doesn't display until the 4 thumbs are rolled over then it's OK.

    Thinking about it, it's only that image so I can just preload that one and I should be able to do that dynamically with a variable.

    Cheers

    Ian

  4. #4
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by ianric View Post
    Hi

    Thanks for the reply. I'm using the scripterlative Thumbsmart script and the reason for the pre loading is that the main large image sometimes doesn't display until the 4 thumbs are rolled over then it's OK.
    That shouldn't happen - do have a URL?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •