JavaScript Developer Guide
Introduction
By default, the Magento application uses the RequireJS file and module loader to optimize the time of loading pages with included JavaScript files, and to manage dependencies of JavaScript resources.
You can follow the same approach when customizing Magento JavaScript, or disable all the default scripts and their load by RequireJS.
For information about how JS resources are located and configured, see the JavaScript resources topic in the Configuration Guide.
What’s in this guide
Topics of this book describe the following:
- JavaScript initialization - how to initialize JavaScript components and widgets in JavaScript files and
.phtml
templates - Use custom JavaScript - how to extend or replace default JavaScript components/widgets.
- Locate JavaScript components - how to define which components (scripts) are used on a particular store page.
- Magento jQuery widgets - Magento jQuery widget API documentation.
- Customizing JavaScript illustration - practical illustration of custom widgets related tasks.
JavaScript automatic testing is described in a separate JavaScript unit testing topic.
Terms used
Term | Description |
---|---|
JavaScript component (JS component) | Any separate .js file decorated as AMD module. |
Ui component | JS component located in the Magento_Ui module, in the app/code/Magento/Ui/view directory, or JS component that extends files from this module. |
jQuery UI widget | A JS component/widget provided by the jQuery UI library used in Magento. |
jQuery widget | Custom widget created using jQuery UI Widget Factory and decorated as AMD module. Many Magento JS components are the jQuery widgets. |