Common JS Cmd/amd What is the difference between the links between them

Source: Internet
Author: User

Know that JS has modular development, but also occasionally heard the name Requirejs,amd,cmd and so on, even when using node, but also used require and other methods, but there has been no clear understanding and concepts. Presumably this is a common condition for many novices who have just come into contact with this knowledge. In fact, just do some basic work, do not need to have too much understanding of them, know how to use on the line, what he is the idea of what to achieve it. Then the man was lazy. Finally, one day, determined to make this piece of knowledge clear, at least there is a clear understanding of this, no longer so hazy, A/C is not divided. Check some articles blog and the answer, found that most of the article in a certain part will be very detailed, too detailed, but not a coherent, I think this is not suitable for my situation of the novice, at least I spent a lot of time, And I write this article is hoping and I have this confused novice can quickly understand these standards, do not want to go deep, read my summary of a few knowledge points, you should be able to no longer look for other articles.   Knowledge Point 1:amd/cmd/commonjs is the standard of JS Modular development, the corresponding realization is requirejs/seajs/nodejs.  knowledge point 2:commonjs mainly for the service end, amd/ CMD is mainly for the browser side, so the most easily confused is amd/cmd. (By the way, what's the difference between a server-side and a browser-side?) The server side generally uses the synchronous loading file, namely needs a module, the server side then stops, waits for it to load to execute. If there are other backend languages, such as Java, the experienced ' player ' should be easier to understand. and the browser side to ensure efficiency, need to use asynchronous loading, which requires a preprocessing, in advance to the required module files in parallel loading good.   Knowledge points 3:amd/cmd difference, although all are parallel loading JS file, but there is a difference, AMD is preloaded, in parallel loading JS file, but also parse the execution of the module (because it also needs to execute, so before loading a module, the module's dependency module needs to be loaded first) , and cmd is lazy loading, although the JS file will be loaded in parallel in the beginning, but will not execute, but only when needed to execute.   Knowledge points 4:amd/cmd advantages and disadvantages. One of the pros is another drawback, you can view the comparison.                 AMD Benefits: Fast loading, especially when you encounter multiple large files Multiple files can be parsed at the same time because of parallel parsing。                 AMD Cons: Parallel loading, asynchronous processing, Loading order is not necessarily, may cause some trouble, even for the program to bury the big pits.                  CMD advantages: Because only in the use of the parsing of the execution of the JS file, therefore, each JS file execution order in the code is reflected, is controllable.                 cmd disadvantage: The execution wait time is superimposed. Because each file executes synchronously (serial execution), time is the sum of all file resolution execution times, especially if the file is large.   Knowledge Point 5: How to use? Commonjs, because Nodejs is its implementation, so using node is OK, and you don't have to introduce other packages. AMD is the introduction of Requirejs through <script> tags, the specific syntax or to see the official documents or Baidu it. CMD is the introduction of SEAJS.

Common JS Cmd/amd What is the difference between them and their connection

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.