SoFunction
Updated on 2025-04-10

JS lazy loading speed up page opening sample code

First, JS lazy loading

The code is as follows:
Copy the codeThe code is as follows:

<script language="JavaScript" src="" ></script>
<script language="JavaScript">
setTimeout("('my').src='include/...file...php'; ",3000);//Delay 3 seconds
</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 it to a small picture you like. It looks very AJAX effect.

Then insert at the bottom of the page:
Copy the codeThe code is as follows:

<SPAN class=spanclass id=AD_L4EVER>
Your JS code is here!</SPAN>
<script>=AD_L4EVER.innerHTML;AD_L4EVER.innerHTML="";</script>

Third, JS finally loaded

Where to display ads
<div ></div>

Ad content you want to display
Copy the codeThe code is as follows:

<div style="display:none">
<script language="javascript" src="/include/.......js"></script>
</div>

Determine whether the ad position to be displayed exists
Copy the codeThe code is as follows:

<script language="javascript">
function chkdiv(divid){
var chkid=(divid);
if(chkid != null)
{return true; }
else
{return false; }
} Finally, the ad is displayed
if (chkdiv('guangg1')) {
('guangg1').innerHTML= ('ggad1').innerHTML;
('ggad1').innerHTML="";
}
</script>

setTimeout usage

The standard syntax of setTimeout is: setTimeout (expression, time (milliseconds)) two parameters.

Here we focus on remembering that the first parameter is a function call, assuming it is a function.

1. Function has no parameters:

function alertV(){ alert("000"); }

When the first parameter is not quoted ("" or ''), one second delay:
setTimeout(alertV,1000);

When the first parameter is added with quotes, delay by one second:
setTimeout("alertV()",1000);

2. The function has parameters:

function alertV(event){ alert("keyCode="+); }

At this time, it should be set to:
setTimeout(function(){alertV(event);},1000); otherwise, the parameter will be not defined.