Load image from another location if server is lagged

Discussion in 'JavaScript' started by forumposters, Jun 13, 2007.

  1. #1
    What I'd like to do is host my images remotely, but only if the remote host is able to load my images in a short amount of time. Can javascript be used to start a timer when the page is first hit and if certain images are not loaded in 5 seconds, then use a different url (at a different server) for the images? If so, can anyone help me get started coding this? Any other ideas on how to better code this task?
     
    forumposters, Jun 13, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Not really, there are no events triggered when an image finished loading by default and so theres no way to tell when the user has all the data
     
    krakjoe, Jun 13, 2007 IP
  3. forumposters

    forumposters Peon

    Messages:
    270
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What about using .complete?
     
    forumposters, Jun 14, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    good thinking :)

    it would seem that onload works however I dont have any ideas on how to make it wait and then swap the image over, if I get any I'll post em .....

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    	
    <body>
    <img src="http://www.webreference.com/i.gif" id="img" />
    <script language="javascript">
    	document.getElementById('img').onload=function()
    	{
    		alert( 'onload triggered' );
    	}
    </script>
    </body>
    </html>
    
    HTML:
     
    krakjoe, Jun 14, 2007 IP