异步加载javascripts

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异步加载javascripts相关的知识,希望对你有一定的参考价值。

  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. <meta name="generator" content="HTML Tidy for Mac OS X (vers 1 September 2005), see www.w3.org" />
  6. <script type="text/javascript">
  7. //<![CDATA[
  8. 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)};
  9.  
  10. // async loading of javascript files, starting asap.
  11. L("http://example.com/example.js",function () {
  12. doSomething();
  13. });
  14. L("http://example.com/foo.js", function () {
  15. fooSomeBar();
  16. });
  17. //]]>
  18.  
  19. <title>Javascript loading example</title>
  20. </head>
  21.  
  22. <p>When the JS loads, you'll see something being done, and some bar being fooed.</p>
  23. </body>
  24. </html>
  25.  

以上是关于异步加载javascripts的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript异步编程 异步的脚本加载

JavaScript异步加载

javascript脚本如何异步加载,有啥作用

使用async属性异步加载执行JavaScript

使用async属性异步加载执行JavaScript

javascript 异步加载