CommonJS, AMD, and CMD differences

Source: Internet
Author: User

This article is referenced from: https://www.cnblogs.com/chenguangliang/p/5856701.html

1, CommonJS

Nodejs is the implementation of COMMONJS specification, Webpack is also in the form of Commonjs to write. node. JS uses the JavaScript language for server-side programming.

2. AMD

Based on the COMMONJS specification of the Nodejs out, the service-side module concept has been formed, very naturally, we want the client module. And it is best to be compatible, a module without modification, both server and browser can be run. However, due to a significant limitation, the COMMONJS specification does not apply to the browser environment .

var math = require (' math '); Math.add (2, 3);

The second line, Math.add (2, 3), runs after the first line of require (' math '), so it must wait until the math.js load is complete. That is, if the load time is long, the entire application will stop there and so on. you'll notice that require it's synchronized.

This is not a problem on the server side, because all the modules are stored on the local hard disk, can be loaded synchronously, waiting time is the hard disk read time. However, for the browser, this is a big problem, because the modules are placed on the server side, the waiting time depends on the speed of the network, it may take a long time, the browser is in "Suspended animation" status.

As a result, the browser-side module cannot be "synchronous-loaded" (synchronous) and can only take "asynchronous load" (asynchronous). This is the background to the birth of the AMD specification.

AMD is the abbreviation for "Asynchronous module definition", meaning "async module definition". It loads the module asynchronously, and the module's load does not affect the execution of the statement behind it. All statements that rely on this module are defined in a callback function that will not run until the load is complete.

3, CMD

The CMD is highly dependent on the nearest, AMD is highly dependent on the predecessor.

CommonJS, AMD, and CMD differences

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.