Wednesday, November 6, 2013

make javascript Speed Up (2)

Asynchronous Transfer Mode getting script

function loadScript


this is sample

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Hello</p>
<script>
 window.onload = loadAllScript;
 function loadScript(url, callback){
  var script = document.createElement("script");
  script.type = "text/javascript";
  console.log('loadScript');
  if(script.readState){ //IE
   script.onreadystatechange =function(){
    if(script.readState =="loaded" || script.readyState =="complete"){
     script.onreadstatechage= null;
     callback();
    }
   };
  }else{ //ELSE
   script.onload=function(){  
    callback();
   };
  }

  script.src=url;
  document.getElementsByTagName("head")[0].appendChild(script);

 }

 function loadAllScript(){
  console.log('loadAllScript');
  loadScript("http://code.jquery.com/jquery-1.10.1.min.js", function(){
 
   loadScript("http://s1.daumcdn.net/cfs.tistory/v/130502110925/blog/plugins/A_ShareEntryWithSNS/script/shareEntryWithSNS.js", function(){
    alert();
   });
  });
 }
</script>
</body>
</html>

No comments:

Post a Comment