Delay loading JS code to improve speed:
If you have a large number of JavaScript code in your Web page that can greatly affect the speed of your Web page, here's a quick introduction to how to handle this problem.
One. Delay Loading JS file:
You can use the Timer function settimeout () to delay loading external JS files, for example:
<Scripttype= "Text/javascript"src=""ID= "my"></Script> <Scripttype= "Text/javascript"> varJS=document.getElementById ("my"); functionAddjs () {js.src="Js/js.js"; } SetTimeout (Addjs, the);</Script>
The above code can realize the JS code 3 seconds before loading, so as to improve the speed to a certain extent.
Two. Place the JS code behind the page content:
This is relatively simple, needless to say, is to put the JS code behind the content of the Web page, one is placed at the bottom of the body, so that you can load the content before the execution of JS code, but also to improve a certain speed.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8348
For more information, refer to: http://www.softwhy.com/javascript/
Delay loading JS code to improve speed