Modular development--sea.js

Source: Internet
Author: User

Do you often encounter problems when your website is developing more and more complex?
1. Conflict
2. Performance
3. Reliance
If these questions are often encountered during multi-person development or in complex development processes,
Can be solved with modular development.
How did the above problem arise?
1. Conflict: If you write a commen.js, this JS file is mainly about writing some
Common methods, such as tab tab, drag-and-drop, etc... When you've written these JS.
may be handed over to colleagues. Colleagues first introduced this JS file, it is possible this page and
To a new colleague to develop, this colleague wrote a function, called tab, when this
tab in the common JS file you write the tab method in the conflict caused the page
When a problem arises, your colleague will negotiate a solution with you and your colleague can change from
The worst case scenario is that your new colleague cites a plugin, such as
: Xxx.js, if there is a conflict, your colleague may negotiate a change of name with you. You may
This time will go to your public JS modified, with a namespace, this method can be
To reduce conflicts, but not to avoid them altogether. The reason is that some companies have more front-end
, so namespaces are still prone to conflict.
2. Performance: Assuming the same, now the page is developed by your colleague, on the new page
May use only one function in the face, if the whole public JS is introduced to the page
is not very reasonable, because we only use one method, the other method can not be used to
Would waste a lot of resources that were requested in vain. At this point our solution is to split
JS, the separate JS method to write to a JS file, which is required to introduce different
JS, so that the performance improvement, then the new problems followed, the introduction of these JS files
If you are independent of each other, if there is mutual dependence on the more troublesome, need to pay attention to the placement of shun
Order and so on.
3. Reliance. For example, you wrote a JS file: Text.js, how to use: Text ();
Your colleague to use, first introduced the JS file, and then normal call, looking at not asking
Problem, and your colleague found that the file relied on another file.
A.js, this time solved. After a few days of product demand, need to add some work
Can, Text.js also need to rely on b.js, you need to tell colleagues, and then introduce B.js, then
Your colleague has been very upset, he may have many pages have been called, need to change very
More. If the product needs to be changed, b.js do not need, need to delete, you tell your colleague to delete, then your colleague found that the page problem, because the deleted files have dependencies ... This is the problem of dependence. So we modify the bug, most of the work is to modify the bug, overtime is unavoidable. If we can avoid these problems, we can save a lot of effort in our work.

The above problems can be solved by modularization.

Sea.js:
A module loader for web-side. To solve the above problems, improve
Code maintainability.

Module concept: In order to improve performance, we put a method into a JS, press
It is necessary to introduce performance improvement, and to solve the dependency conflict and performance through the modular library.
Problem, we think of each JS file as a module.

Sea.js using:
1. Introduction of libraries
2. How do I become a module?
----define


3. How to invoke a module
----Export
----Seajs.use
4. How to resolve dependencies?
----Require

Modular development--sea.js

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.