first, Equirejs and Seajs are very good module loader, the difference is as follows
1. There are differences between the two positions. Requirejs want to be a browser-side module loader, and also want to be a module loader for Rhino/node and other environments. Seajs is focused on the Web browser side, while the node extension can be easily run on the node server side
2. There are differences in the standards that they follow. Requirejs follows the AMD (asynchronous module definition) specification, and Seajs follows the CMD
Requirejs will let you write JavaScript in a different way than usual. You will no longer use the script tag to introduce JS files in HTML and to manage dependencies without the script tag order. There will be no blockage (blocking) happening
Second, the Requirejs module entrance
A custom attribute on the script tag: data-main= "Main", the main.js to the right of the equal sign. This main refers to the main module or the Ingress module.
Main.js calls Require.config and require in two functions.
Require.config is used to configure some parameters that will affect some of the behavior of the Requirejs library.
Require.config parameter is a JS object, commonly used configuration has baseurl,paths and so on.
<script data-main="js/main" src="require.js.js"> </script>
Main.js
1 require.config ({2 paths: {3 'jquery-1.7.2') 4 }5}); 6 7 require (['jquery'], function ($) {8 Alert ($ (). jquery); 9 });
The paths parameter, using the module name "jquery", whose actual file path jquery-1.7.2.js (suffix. js can be omitted).
We know that jquery has been supporting the AMD specification since 1.7, that is, if jquery is running as an AMD module, its module name is "jquery". Note that "jquery" is fixed and cannot be written "jquery" or anything else.
Note: If you change the file name "Jquery-1.7.2.js" to "jquery.js", you do not have to configure the paths parameter.
first, Equirejs and Seajs are very good module loader, the difference is as follows
first, Equirejs and Seajs are very good module loader, the difference is as follows
Requirejs-Modular Development Framework