Posted By

johnloy on 08/05/09


Tagged

ajax javascript textmate performance optimization


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

inkdeep
legacye


asynchronous loading of javascripts


 / Published in: Other
 

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <meta name="generator" content="HTML Tidy for Mac OS X (vers 1 September 2005), see www.w3.org" />
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. function L(B,D){var A=document.createElement("script"),C=document.documentElement.firstChild;A.type="text/javascript";if(A.readyState){A.onreadystatechange=function(){if(A.readyState=="loaded"||A.readyState=="complete"){A.onreadystatechange=null;D()}}}else{A.onload=function(){D()}}A.src=B;C.insertBefore(A,C.firstChild)};
  10.  
  11. // async loading of javascript files, starting asap.
  12. L("http://example.com/example.js",function () {
  13. doSomething();
  14. });
  15. L("http://example.com/foo.js", function () {
  16. fooSomeBar();
  17. });
  18. //]]>
  19. </script>
  20.  
  21. <title>Javascript loading example</title>
  22. </head>
  23.  
  24. <body>
  25. <p>When the JS loads, you'll see something being done, and some bar being fooed.</p>
  26. </body>
  27. </html>
  28.  

Report this snippet  

You need to login to post a comment.