There are two types of standard JavaScript modules: Commonjs and AMD
Let's talk about Commonjs.
CommonJS-Do you think JavaScript is just a client-side compilation language, in fact JavaScript design is not just for the client design language. Later, just because of the rapid popularity of the web, coupled with Netscape and Microsoft's dispute between the premature javascipt standardization. To learn more about the JS history please see: Http://zh.wikipedia.org/zh-cn/JavaScript. The premature standardization of JS led to many of the pitfalls of JS and the lack of standard libraries, even if this does not affect the JS to become a good programming language (such as the very popular now node. js). Currently JS only includes the basic API, if you want to be a server-side programming language, such as IO, FS, i18n, package and so on features are not, COMMONJS is an organization, it lets JS in a common direction to make efforts to improve JS. As far as possible common JS has not yet a formal release, but many directions of the implementation of the draft has achieved very good results. For example, node. js is now very popular. Back to the topic of this article, COMMONJS and Amd,requirejs have what relationship? It turns out that commonjs one of themModules Specification, we are all like JS now so everything is written in a file to write server-side applications is a very difficult thing, it is tosolve JS does not have the modular management code function。 The key part is two functions: require-used to import dependent export-used to export modules, including identifiers (identifier) and module contents (contents) Commonjs is not just a specification, just like interface in Java, Does not indicate how you should achieve. The problem is that COMMONJS's modules specification was designed for server-side design, which is a synchronous pattern. But this model is not suitable for the browser side, we imagine if the browser synchronization mode one load module, then open will become very slow, so AMD is for this birth, its biggest feature is that canasynchronously loading a module, the difference is that AMD has a define function that allows the current module to load the module that the current module depends on, such as the meaning of the following definition is to load the dependent module, dependency, and array module before running function. define (' module/id/string ', [' module ', ' dependency ', ' Array '], function (module, dependency, array) { return modulecontents; }); so Commonjs module and AMD are JS modular definition API, from the same origin, is can let JS can be modular loading. So Requriejs is actually the most widely and most popular implementation of AMD now. The introduction on the Requirejs website actually explains the reason why Requirejs was born, but I didn't understand it at that time. requirejs is a javascript file and module loader. It's optimized for in-browser use, but it can be used in the other JavaScript environments, like Rhino and Node. Using a modular script loader like Requirejs would improve the speed and quality of your code. From the above basic can see COMMONJS (General modules specification ), AMD and Requirejs prior to the relationship. In short, COMMONJS modules and AMD are all designed to solve the JS Modular specification API,COMMONJS more suitable for server side, and AMD is basically for the browser side (but it can also be used on the server side, such as node Loader's direction of effort: http://requirejs.org/docs/node.html), and Requirejs is the most popular implementation of AMD. http://www.2cto.com/kf/201401/270303.html
JavaScript JavaScript Modular Programming-CommonJS, relationship between AMD and Requirejs