Make JavaScript Load Last?

Discussion in 'JavaScript' started by Crazace2006, Dec 21, 2007.

  1. #1
    I just built www.LeftyStrats.com, but the site loads slow because of the ebay ads which are done in javascript. The problem is the body of the page and all the content has to wait for them to load before anything will appear.

    I was wondering if there was a way to make the ebay ads load last. I tried to put defer="defer" in the script but it just made them the only things on the page. Any advice would be helpful.

    Thanks
     
    Crazace2006, Dec 21, 2007 IP
  2. godkillah

    godkillah Guest

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you could add a element for it and than at the bottem of the page use a javascript to add the ads in the element

    for example:

    >Banner
    ><div id='ads'>Loading ads</div>
    >Site content
    >copyright
    >document.getElementById("ads").innerHTML='ebay ads'
     
    godkillah, Jan 6, 2008 IP
  3. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Good question.

    Possible solutio:
    
    window.onload = function(){ //load the ads after everything else has already loaded
    	var ebayAds = document.createElement('script');
    	ebayAds.src = 'http://lapi.ebay.com/ws/eBayISAPI.dll'; //Path to js file.
    	ebayAds.type = 'text/javascript';
    	document.body.appendChild(ebayAds);
    }
    
    PHP:
    I use window.onload because it only fires after everything has loaded. :)

    @godkillah: You're telling me you know JavaScript? :rolleyes:
     
    MMJ, Jan 6, 2008 IP
  4. blacknet

    blacknet Active Member

    Messages:
    709
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    70
    #4
    try adding the defer attribute in first.. may well work, failing that the onload method

    <script src="" defer="defer"></script>
     
    blacknet, Jan 7, 2008 IP
  5. midhunhk

    midhunhk Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try this
    <body>
    ....
    </body>
    <script language="" src="some script"></script>
    </html>
     
    midhunhk, Jan 9, 2008 IP
  6. aliefmaksum

    aliefmaksum Peon

    Messages:
    56
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This work fine with text/plain html, but if i insert javascript like google it doesn't work. Can you help me? :confused:
     
    aliefmaksum, Nov 25, 2008 IP