Results 1 to 5 of 5

Thread: Load images in a certain order?

  1. #1
    Join Date
    Nov 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Load images in a certain order?

    Hello,

    I am looking for a script that can load the images in the order I want them to be loaded.

    I added a new picture to a site I am making and it is placed in the top of the page.
    The problem is because it is the newest one it's loading all the other images
    before this one, or maybe because of another reason?
    But because this is the first image the viewer see I want it
    to load first and not last.

    Is there a script that can give me the possibility to choose which picture loads first,
    or a script that will load first the picture that was added last?

    Thank you,

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    I've noticed things like that. You could try preloading it in the head of the page:

    Code:
    <script type="text/javascript">
    var pimg=new Image();
    pimg.src='image_name.gif';
    </script>
    But, I think that the only way to be reasonably sure (the above can only work if javascript is enabled on the client side and may not work in some browsers even with javascript enabled) is to do both of the below:

    1 ) Regardless of where the image appears in the layout, make sure that it appears before all others in the HTML markup code of the page.

    and:

    2 ) Download all of your images that appear on the page. Then delete them all from the server. Then upload them to the server, one at a time, in the order in which you want them to be served.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2004
    Posts
    9,902
    Thanks
    3
    Thanked 967 Times in 955 Posts
    Blog Entries
    15

    Default

    Like John said, I think your best bet is to preload all the images first using JavaScript. That way, all images have an equal chance of getting loaded before the other one. You can use a script like the below in the HEAD section of your page:

    Code:
    <script type="text/javascript">
    
    function preloadimages(){
    var myimages=new Array()
    for (i=0;i<preloadimages.arguments.length;i++){
    myimages[i]=new Image()
    myimages[i].src=preloadimages.arguments[i]
    }
    }
    
    //Enter path of images to be preloaded inside parenthesis. Extend list as desired.
    preloadimages("http://mydomain.com/firstimage.gif","http://mydomain.com/secondimage.gif","http://mydomain.com/thirdimage.gif")
    
    </script>

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by ddadmin View Post
    Like John said, I think your best bet is to preload all the images first using JavaScript. That way, all images have an equal chance of getting loaded before the other one. You can use a script like the below in the HEAD section of your page . . .
    That is not what I said. I said that if you want a particular image to display first on a page, preload only that image and do it in the head. I think that if you preload all of the images, there is a good chance that they will simply be served in the same order as they were uploaded to the server, not really changing anything, or perhaps delaying the onset of the loading of the page's content until all images are cached - still not the result I think we are looking for here.

    To get the effect of a normal page load, preload only the image(s) you are concerned about. Also, as I did say, preloading depends upon javascript so, the better method I think would be as outlined in the two step process in my previous post in this thread.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for both your replies,

    I see it's not as simple as I thought it should be,
    and on the other hand not as hard as I might think it is.

    I will give it a go and see how it go's.

    Thank you very much.

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
  •