[go: nahoru, domu]

Jump to content

Asynchronous module definition: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Grammar fix
Reverted 1 edit by 2401:E180:8871:912C:FA78:71FB:864B:3ADD (talk): Editing mistake?
 
(46 intermediate revisions by 35 users not shown)
Line 1: Line 1:
[[File:Asynchronous Module Definition overview vector.svg|thumb|Instead of loading files one after the other, AMD can load them all separately, even when they are dependent on each other.]]
{{Underlinked|date=September 2013}}


'''Asynchronous module definition''' ('''AMD''') is a [[Specification (technical standard)|specification]] for the programming language [[JavaScript]]. It defines an [[application programming interface]] (API) that defines [[modular programming|code modules]] and their [[Coupling (computer programming)|dependencies]], and loads them asynchronously if desired. Implementations of AMD provide the following benefits:
[[File:Asynchronous Module Definition overview.png|thumb|Instead of loading files one-after-the-other. AMD can load them all separately, even when they are dependent on each other.]]
* Website performance improvements. AMD implementations load smaller JavaScript files, and then only when they are needed.
* Fewer page errors. AMD implementations allow developers to define dependencies that must load before a module is executed, so the module does not try to use outside code that is not available yet.


In addition to loading multiple JavaScript files at runtime, AMD implementations allow developers to encapsulate code in smaller, more logically-organized files, in a way similar to other programming languages such as [[Java (programming language)|Java]]. For production and deployment, developers can [[Concatenation|concatenate]] and [[Minification (programming)|minify]] JavaScript modules based on an AMD API into one file, the same as traditional JavaScript.
'''Asynchronous module definition''' ('''AMD''') is a [[JavaScript]] [[API]] for defining modules such that the module and its dependencies can be asynchronously loaded. It is useful in improving the performance of websites by bypassing synchronous loading of modules along with the rest of the site content.


AMD provides some [[CommonJS]] interoperability. It allows for using a similar {{code|exports}} and {{code|require()}} interface in the code, although its own {{code|define()}} interface is more basal and preferred.<ref>{{cite web |title=AMD specification |url=https://github.com/amdjs/amdjs-api |website=GitHub |publisher=Group for AMD JS Module API |access-date=28 October 2019 |date=28 October 2019}}</ref>
In addition to loading multiple JavaScript files at runtime, AMD can be used during development to keep JavaScript files encapsulated in many different files. This is similar to other programming languages, for example Java, which support keywords such as import, package, and class for this purpose. It is then possible to concatenate and minify all the source JavaScript into one small file used for production deployment.

The AMD specification is implemented by [[Dojo Toolkit]], RequireJS, and other libraries.<!-- Do not link terms until an article exists. -->


==References==
==References==
{{Reflist}}
* [https://github.com/amdjs/amdjs-api/wiki/AMD AMD API wiki]

==External links==
* {{official website|https://github.com/amdjs/amdjs-api}}
* [http://requirejs.org/docs/whyamd.html Why AMD? (Require.js)]
* [http://requirejs.org/docs/whyamd.html Why AMD? (Require.js)]
* [http://dojotoolkit.org/documentation/tutorials/1.8/modules/ Dojo Tutorial: AMD Modules]
* [http://dojotoolkit.org/documentation/tutorials/1.10/modules/ Dojo Introduction to AMD]
* [http://addyosmani.com/writing-modular-js/ Writing Modular JavaScript With AMD, CommonJS & ES Harmony]


{{ECMAScript}}
{{ECMAScript}}
Line 17: Line 25:
[[Category:Application programming interfaces]]
[[Category:Application programming interfaces]]
[[Category:Web development]]
[[Category:Web development]]


{{prog-lang-stub}}

Latest revision as of 02:09, 10 March 2024

Instead of loading files one after the other, AMD can load them all separately, even when they are dependent on each other.

Asynchronous module definition (AMD) is a specification for the programming language JavaScript. It defines an application programming interface (API) that defines code modules and their dependencies, and loads them asynchronously if desired. Implementations of AMD provide the following benefits:

  • Website performance improvements. AMD implementations load smaller JavaScript files, and then only when they are needed.
  • Fewer page errors. AMD implementations allow developers to define dependencies that must load before a module is executed, so the module does not try to use outside code that is not available yet.

In addition to loading multiple JavaScript files at runtime, AMD implementations allow developers to encapsulate code in smaller, more logically-organized files, in a way similar to other programming languages such as Java. For production and deployment, developers can concatenate and minify JavaScript modules based on an AMD API into one file, the same as traditional JavaScript.

AMD provides some CommonJS interoperability. It allows for using a similar exports and require() interface in the code, although its own define() interface is more basal and preferred.[1]

The AMD specification is implemented by Dojo Toolkit, RequireJS, and other libraries.

References[edit]

  1. ^ "AMD specification". GitHub. Group for AMD JS Module API. 28 October 2019. Retrieved 28 October 2019.

External links[edit]