What's the best way to offer javascript embed that won't slow a page down?

Posted by Shpigford on Stack Overflow See other posts from Stack Overflow or by Shpigford
Published on 2010-03-25T22:19:44Z Indexed on 2010/03/25 22:23 UTC
Read the original article Hit count: 295

Filed under:
|

I have a chunk of javascript that users can copy and paste to put on their sites.

I'm currently using the following code (ala WEDJE) that allows the rest of the page to load even if my script is slow or not responding.

<script type="text/javascript">
  var number = "987654321";
  var key = "123abc";

  (function(){
    document.write('<div id="ttp"></div>');
    s=document.createElement('script');
    s.type="text/javascript";
    s.src="http://example.com/javascripts/embed.js?" + Math.random(); 
    setTimeout("document.getElementById('ttp').appendChild(s);",1);
  })()
</script>

But that method is a few years old and so I wasn't sure if there was a more efficient way of doing the same thing that others have come up with.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about embed