search

AMD

AMD stands for Asynchronous Module Definition. It is an alternative to CommonJS (CJS) specification.

The API specifies a mechanism for defining modules such that the module and its dependencies can be asynchronously loaded. This is particularly well suited for the browser environment where synchronous loading of modules incurs performance, usability, debugging, and cross-domain access problems.

AMD libraries expose a global define function whose footprint is

define(modulename?,[dependencyA?, dependencyB?, ], function (objectA, objectB, ) {
...
    var myExportedObj = function() {  }
    return myExportedObj;

});

Where

Aside from the global define function, an AMD compliant library must have a define.amd property whose value is an object. Checking for the existence of both define and define.amd in the global scope allows any script to verify it is being called from an AMD loader.

Examples of libraries providing AMD loading capabilities are:

All these libraries allow for the developer to preview a project without any build step, requesting the dependencies asynchronously. There’s usually an optional (but reccomended) build or bundling step for production deploys, in order to minify the code and minimize the number of requests in order to enhance load times. Allegedly, the coming of HTTP2 support in browsers and webservers should eliminate the need for extra requests when loading dependencies asynchronously, thus eliminating the need of a build step.

Other libraries that can’t load dependencies asynchronously but can include AMD modules in their build workflow, are, for example: