After the page is fully loaded, execute JS

Source: Internet
Author: User

Defer attribute in script
If you are a person who cares about and cares about system performance, I think you should be interested in defer in the script.
The defer attribute in script is false by default. According to the descriptions in the DHTML programming guide, the defer attribute is written as follows:
Using the attribute at design time can improve the download performance of a page because the browser does not need to parse and execute the script and can continue downloading and parsing the page instead.
That is to say, if the defer attribute is added during script writing, the browser does not need to process the script immediately when downloading the script, but continues to download and parse the page, this will improve the download performance.
There are many such cases. For example, you have defined many JavaScript variables, or (. INC) has written a lot of scripts to be processed, so you may wish to add the defer attribute to these scripts to improve performance.
Example:
<Script language = "JavaScript" Defer>
VaR object = new object ();
....
</SCRIPT>
Because the default defer attribute is false, <script language = "JavaScript" Defer> explicitly declaring the defer attribute is equivalent to <script language = "JavaScript" Defer = true>
After the defer attribute is declared, you must determine whether other variables reference the variables in the defer script block. Otherwise, script errors may occur.

Combined with <body onload = "XX ()">

And

<SCRIPT defer = "Defer">

XX ();

</SCRIPT>

The JS will be executed after the page is loaded, including IFRAME loading.

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.