Home  >  Article  >  Web Front-end  >  JS delayed loading speeds up page opening speed sample code_javascript skills

JS delayed loading speeds up page opening speed sample code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:06:081125browse
First, JS lazy loading

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




Second, JS is loaded last

Insert the following code where JS needs to be inserted:

LOADING...< ;/SPAN>

Of course, that LOADING... you can change it to a small picture you like. It looks very AJAX effective.

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


Yours The JS code is here!

<script>L4EVER.innerHTML=AD_L4EVER.innerHTML;AD_L4EVER.innerHTML="";</script>

Third, JS Finally load

where you want to display ads


where you want to display ads
Copy code The code is as follows:



Judgment Whether the ad position to be displayed exists
Copy the code The code is as follows:



setTimeout usage

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

Here it is important to note the call when the first parameter is a function, assuming it is a function.

1. Function has no parameters:

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

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

When the first parameter is added with quotation marks, delay for one second:
setTimeout("alertV()",1000);

2. The function has parameters:

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

At this time it should be set to:
setTimeout(function(){alertV(event);},1000); Otherwise, it will prompt that the parameter is undefined.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn