Delay loading JS code to improve speed

Source: Internet
Author: User

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

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.