JS delay loading speeds up page opening

Source: Internet
Author: User

  Use JS delay loading can speed up the opening, there are several good examples, interested friends can refer to the following

First, JS delay loading     code as follows:  code as follows: <script language= "JavaScript" src= "" id= "my" ></script>  < Script language= "JavaScript" >  settimeout ("document.getElementById" (' my '). src= ' include/... File ... php '; ", 3000)//Delay 3 sec   </script>    Second, JS finally loaded     insert the following code where you need to insert JS:    <span id= l4ever>loading...</span>    Of course, that LOADING ... You can change to a small picture of your own. .    then insert the:  code at the bottom of the page as follows: <span Class=spanclass id=ad_l4ever>  Your JS code is here!</span>  <script>L4EVER.innerHTML=AD_L4EVER.innerHTML; Ad_l4ever.innerhtml= "" ";</script>    third, JS final load     want to show the location of the ad   <div id=" GUANGG1 "> </div>    Want to display the advertising content   code as follows: <div id= "Ggad1" style= "Display:none" >  <script language= "JavaScript" src= "/include/.......js" ></script>  </div>    to determine if the advertising position to display exists   code as follows: <script language= "javascript" >  function chKdiv (divID) {  var Chkid=document.getelementbyid (divid);  if (chkid!= null)   {return true;}   else  {return false;}  } Finally, the advertisement is displayed   if (Chkdiv (' Guangg1 ')) {  document.getElementById (' Guangg1 '). innerhtml= document.getElementById (' ggad1 ') .innerhtml;  document.getElementById (' Ggad1 '). innerhtml= ""; }  </script>    settimeout usage     SetTimeout's standard syntax is: settimeout (expression, time (milliseconds)) two parameters .    Here it is noted that the first parameter is called when a function is invoked, assuming that it is a functional .    1. function:    function Alertv () {alert ("000");}     When the first argument is not quoted ("" or "), the delay is one second:  settimeout (alertv,1000);    Delay one second when the first argument is quoted again:  SetTimeout ("Alertv ()", 1000);    2. function has parameter:    function Alertv (event) {alert ("keycode=" +event.keycode);}     This should be set to:  settimeout (function () {ALERTV (event);},1000); Otherwise, the parameters are not defined .   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.