ICAEW.com works better with JavaScript enabled.
Your current browser is not capable of using this site without JavaScript. Please use an updated browser or enable JavaScript to continue.

How to add a new component using require.js

To add a new js component using require, save the new JS file into the js directory structure (e.g /js/corporate/myscript.js). In the markup that uses this script, add the attributes data-require=“corporate/myscript” to the containing element.

main.js will crawl the page looking for any data- attributes and run these through require. For simple, direct calls, the value of the data-require parameter with tell require.js where to get the file. For the example “corporate/myscript”, the path to corporate is defined in app.js so require will look there for a file called myscript.js and load this file whenever that attribute value appears in the page.

More complex components are wrapped in a define function that explicitly states the file name and dependencies that need to load before that file is run. A complex component may include multiple define blocks.

define("global/main",["jquery",
"core",
"bootstrapper"], function ($) {
...});

This explicitly defines “global/main” and that query, core and bootstrapper need to load before this function can be run. The paths to all of these prerequisites are defined in app.js

To instantiate a require module, the file simply needs to be called using the require method, as global/main is at the end of the page once it has loaded.

<script type="text/javascript">
require([“global/main"]);
</script>