Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Background:............................................................................................................... 1
AMD(Asynchronous Module Definition):......................................................................1
Common.js :............................................................................................................... 1
Require.js:................................................................................................................... 1
Conclusion:................................................................................................................. 2
Common.js :
The CommonJS group defined a module format to solve
JavaScript scope issues by making sure each module is executed in its own
namespace. This is achieved by forcing modules to explicitly export those
variables it wants to expose to the universe, and also by defining those
other modules required to properly work.It uses require, module, and exports
free variables, i.e. they're implicit.Benefits provided by Common js are:
It is synchronous in nature.
Best suited for server side development as it is synchronous in nature.
Require.js:
RequireJS is a JavaScript file and module loader. It is optimized for inbrowser use, but it can be used in other JavaScript environments, like Rhino
and Node. Using a modular script loader like RequireJS will improve the speed and
quality of your code.Requirejs provides following benefits:
Conclusion:
AMD gives us more benefits when we want to load the files through
asynchronous calls and commonjs is preferred if we want to make synchronous
calls. As Require.js is a implementation of AMD ,it is well suited for web applications
if we are going to use AMD in our application and also it provides part of commonjs
with a wrapper.