Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    how do you know if preloading works?

    Preloading never seems to work for me. Even for a split second or 2, I see 'X' before the page is done loading, why? And because of the lovely thing that you can't disable known as "cache", there's no way of knowing. I can't test it offline. I tried it on a floppy even after changing to another disk and then replacing the first and the images are still in Windows cache and not loading at floppy speed. And then online, servers handle cache on any files you have loaded and remain that way until that file is modified. Is the term "preloading" just a hoaxe? I want to make my own preload bar.

    <script>
    A=Array("20.gif","21.gif","22.gif","23.gif")
    B=Array("a","b","c","d")
    for (i=0; i<A.length; i++)
    {
    B[i]=new Image()
    B[i].src=A[i]
    grow()
    }

    function grow()
    {
    document.images[0].width+=50
    }
    </script>

    <body>
    <img src="z.gif" width="0" height="16" />
    </body>

    Will this work?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The "z.gif" in your HTML is not the same image object as the one you created in script. Eg if I go

    <script>
    var myImg = new Image;
    myImg.src = "picture.gif";

    document.write('<img src="picture.gif">');
    </script>

    Then you won't see any benefit to the preload, because there's two images there; the fact that they both have the same URI is irrelevant - the browser still loads it twice.

    But this is different; this only loads the image once:

    <script>
    var myImg = new Image;
    myImg.src = "picture.gif";

    document.write('<img src="'+myImg.src+'">');
    </script>

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Location
    West Virginia
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks brothercake for the valuable information -- it is the first time I've read that explanation.

    Quick question... If a person wanted to preload multiple images, is it just a matter of adding them in this manner:

    Code:
    <script> 
    var myImg = new Image; 
    myImg.src = "picture.gif", "picture1.gif", "picture2.gif", "picture3.gif"; 
    
    document.write('<img src="'+myImg.src+'">'); 
    </script>
    Reno CF

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Crossposted; the rest of the thread is at http://www.codingforums.com/showthre...threadid=17645
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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