Chapter 42. Non-AMD Scripts
Whenever possible, JavaScript code should be written as an AMD module. Alternatively, the custom adapter mechanism can be used to adapt scripts to the AMD format.
While this is the recommended practice, it may sometimes be necessary to load scripts as traditional non-AMD modules. This approach is possible, providing the following conditions are met:
- Traditional scripts must be declared using the
<scripts>element instead of<module>. - Dependencies can be declared using the
<depends>element, but the scripts can only depend on other scripts, not on modules.This is also true for modules: a module can only depend on another module, not on a script. - JavaScript code declared in the
<scripts>element is pushed to the HTML head. This means the script will be loaded and executed before a DOM is created, and will likely have an impact on front-end performance.
<scripts> <name>foo</name> <script> <path>/path/to/foo.js</path> </script> <depends> <scripts>bar</scripts> <depends> </scripts>
It is also possible to use a script that is available at a public URL. This can be achieved using the
<url> element instead of <script>:
<scripts> <name>foo</name> <url>http://path.to/foo.js</url> </scripts>
See Also: