Require.js and Sea.js of JavaScript modular programming

Source: Internet
Author: User

Individuals tend to require.js

AMD is the normalized output of the module defined by REQUIREJS during the promotion process.
CMD is the normalized output of the module defined by SEAJS in the process of generalization.
Similar to the CommonJS modules/2.0 specification, is bravojs in the promotion process of the module definition of standardized output.
A lot more?? AMD is the asynchronous module definition, the Chinese name is the meaning of the asynchronous module definition. CMD is the definition of common module definitions, the CMD specification is developed domestically, just like AMD has a Requirejs,cmd browser implementation seajs,seajs to solve the problem and Requirejs, Only when the module is defined and the module is loaded (can be said to run, parse) the timing is different

Requirejs mainly solves two problems

1. Multiple JS files may have dependencies, the dependent files need to be loaded into the browser earlier than the files that depend on it
2, JS load when the browser will stop the page rendering, loading more files, the page lost response time longer

1. First, the difference in principle

Sea.js follows the CMD specification. The writing style is similar to node. JS's writing template code. Automatic loading of dependencies, simple and clear configuration. It's just lazy loading.

Require.js follow AMD specs, CMD and AMD are basically the same, the biggest difference is that cmd is lazy to load, AMD is preloaded.

Simply put, sea.js belongs to lazy loading, require.js belongs to preload.

Here, by the way, extend the pros and cons of preloading and lazy loading

Preload: Loads all files when first accessed

Advantage: Once the first visit is completed, the speed of the visit will be fast

Cons: The first time you load a page waits a long time.

Lazy loading: The corresponding files are loaded when they are used.

Advantage: The first access speed is relatively fast.

Disadvantage: The speed of accessing other new modules becomes slower.

2. Write the distinction above

is to use define to define a template. The function is transferred by the require,exports,module of three parameters.

Basically their usage is very much the same. But the big difference of two points is that you need to pay attention to:

1) sea.js Use the module with the method Seajs.use, and require.js directly with the Require keyword

2) sea.js only one module can be passed in only one string, but require must be an array to pass in.

Require.js and Sea.js of JavaScript modular programming

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.