Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 6 of 6
  1. #1
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default Prototype/ajax - load page before images?

    Most of our pages have a few images on them, and for the page to load, all the images have to load. So some pages take ages to load fully. Which may make people think the page isn't loading.

    So is there any way for the text to be loaded instantly and then the images are loaded as they would be on a normal html page?

  2. #2
    Join Date
    Jul 2008
    Posts
    5,289
    Tokens
    0

    Latest Awards:

    Default

    Code:
     
    <html>
    <body>
    <p>Images:</p>
    <img name=image0>
    <img name=image1>
    <img name=image2>
    <img name=image3>
    End of document body.
    </body>
    <script type="text/javascript">
    function LoadImage(imageName,imageFile)
    {
      if (!document.images) return;
      document.images[imageName].src = imageFile';
    }
    LoadImage('image4','number4.gif');
    LoadImage('image5','number5.gif');
    LoadImage('image6','number6.gif');
    LoadImage('image7','number7.gif');
    </script>
    </html>

  3. #3
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by AlexOC View Post
    Code:
     
    <html>
    <body>
    <p>Images:</p>
    <img name=image0>
    <img name=image1>
    <img name=image2>
    <img name=image3>
    End of document body.
    </body>
    <script type="text/javascript">
    function LoadImage(imageName,imageFile)
    {
      if (!document.images) return;
      document.images[imageName].src = imageFile';
    }
    LoadImage('image4','number4.gif');
    LoadImage('image5','number5.gif');
    LoadImage('image6','number6.gif');
    LoadImage('image7','number7.gif');
    </script>
    </html>
    I mean automatically. We have pages which display all the badges, staff list images etc..

    So preloading them would take too long.

  4. #4
    Join Date
    Jul 2008
    Posts
    5,289
    Tokens
    0

    Latest Awards:

    Default

    That should Delay the Images Loading untill the text context is loaded.

    You can also control which order the images load, might be useful to load the layout then the list of badges etc.

    Found it here: http://www.cryer.co.uk/resources/javascript/script3.htm

  5. #5

    Default

    Well I set myself the challenge to do this in Prototype, as I'm a jQuery lover, and this is what I came up with (if any Prototype expert know how to do it better, please tell me).

    Preview: http://pastebin.me/4a3824d7b2069
    Code:
    Code:
    document.observe("dom:loaded", function(){
      $$('img').each(function(img){
        if (!img.complete) {
          img.hide();
          img.observe('load', function(event){
            event.element().show();
          });
        }
      });
    });
    Last edited by Iszak; 16-06-2009 at 11:20 PM.

  6. #6
    Join Date
    Mar 2008
    Posts
    940
    Tokens
    75

    Default

    Nice one Iszak!

    I'm using it.


Posting Permissions

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