Yui Note 1 module Loading

Source: Internet
Author: User

We usually use the <SCRIPT> label to introduce the script into the page for development. If it is a simple logic, but if it is a large scale JS development, the following problems may occur:

1. <SCRIPT> the tag loading script and execution script are processed together, so developers need to control this process by themselves.

2. <SCRIPT> the tag is a blocking download, which may affect the user experience. Therefore, we recommend that you place the script at the bottom of the page. Some async and defer attributes also solve this problem.

3. <SCRIPT> global variables are shared. That is to say, all the code is executed in one environment and there is no namespace concept, which may easily affect the interaction of codes, for example, the Code introduced later causes the previous code to crash and bugs.

4. <SCRIPT> there is no dependency. The Script Loading usually strictly follows the sequence, so it may cause dependency problems.

The reason for these problems is that the JS environment does not have the module concept in advanced programming languages (such as PHP, Java, C #). To solve these problems, with the development of JS, yui provides a solution: yui3 provides a global object Yui, which is a namespace and includes some basic functions such as loading the registration module. Its advantages include:

1. Decoupling the script registration and execution phases. Yui. Add () loads the code as needed, and Yui. Use () runs these modules in the security sandbox.

2. Yui can load modules synchronously or asynchronously.

3. In addition to some static methods, Yui avoids using the global context environment. The y instance is private and will not be overwritten by the sandbox.

4. Yui supports dependency loading. When the Add module is registered, it can contain some dependency information. When the module is used, this information is used to build the dependency tree and skip the loaded modules.

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.