www.webdeveloper.com
Results 1 to 8 of 8

Thread: [RESOLVED] Preload images checkup

  1. #1
    Join Date
    Aug 2012
    Posts
    43

    resolved [RESOLVED] Preload images checkup

    Hi everyone,
    I'm just wandering if the following script is sufficient to preload my images...

    number_of_images is actually a variable but for clearness i removerd the php code.

    Code:
    // create image object
    preload_image_object = new Image();
    
    // set image url array
    image_url = new Array();
    
    // fill image url array
    var x = 0;
    for(x=0; x<number_of_images; x++){
    	image_url[x] = "images/image_" + x + ".jpg";
    	preload_image_object.src = image_url[x];
    }
    maybe one of you guys want to check the effectiveness?

    Thanx!
    Last edited by Nomistake; 08-26-2012 at 06:43 AM.

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    It is not correct. You need an Image object for each image, you can't re-use the same one.

    The simplest way is this, as long as you don't intend to refer to the Image objects later:
    Code:
    for( var x = 0; x < number_of_images; x++)
       new Image().src = "images/image_" + x + ".jpg";

  3. #3
    Join Date
    Aug 2012
    Posts
    43
    thank you very much.

    so i have this now:

    Code:
    var x = 0;
    for(x=0; x < number_of_images; x++){
    	new image().src = "images/image_" + x + ".jpg";
    }
    am i right i only needs this to make sure the images are already in the cache of the explorer?
    and then later on they are called bij an <img> object which should show the already cached image... ?
    just to be sure
    Last edited by Nomistake; 08-26-2012 at 01:54 PM.

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Nomistake View Post
    am i right i only needs this to make sure the images are already in the cache of the explorer?
    and then later on they are called bij an <img> object which should show the already cached image... ?
    If by 'later on' you mean when another script subsequently loads them into an <img> placeholder, then yes.

  5. #5
    Join Date
    Aug 2012
    Posts
    43
    Well, by 'later on' i mean displaying them like this:
    <img src="images/image_1.jpg" alt="image_1">
    <img src="images/image_2.jpg" alt="image_2">
    etc...
    So it will use the cached?
    ___________________________________
    another thing thats comes to my mind:

    the thing is, depending on which menu item is clicked, the images folder kan be different, but the sequence of the image names remains the same... :

    Code:
    var x = 0;
    for(x=0; x < number_of_images; x++){
    	new image().src = "projects/image_" + x + ".jpg";
    }
    is this a problem?
    will the image \images\image_1.jpg be in cache automatically be overwritten by \projects\images_1.jpg

    sorry for al my questions but as you can see, i'm rather new to this

    Thank you for your time!

  6. #6
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Nomistake View Post
    Well, by 'later on' i mean displaying them like this:
    <img src="images/image_1.jpg" alt="image_1">
    <img src="images/image_2.jpg" alt="image_2">
    etc...
    So it will use the cached?
    No, pre-loading images that are to be displayed initially is pointless.

    will the image \images\image_1.jpg be in cache automatically be overwritten by \projects\images_1.jpg
    No.

  7. #7
    Join Date
    Aug 2012
    Posts
    43
    Wel, they are not displayed initially,
    it's like a photo/image slide show.

    with the above code, i preload the images that will be displayed when the user advances trough the slide show... of course i don't display them directly on the first page :-)

    so i hope my code isnt pointless?

    greetings,

  8. #8
    Join Date
    Aug 2012
    Posts
    43

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles