RequireJS - Dojo


Dojo is a JavaScript toolkit which is based on the AMD module architecture that provides additional modules to add extra functionality to the web application and also saves time and scale in the web application development process.


The following example shows the usage of Dojo along with RequireJS. Create an html file with the name index.html and place the following code in it −

<!DOCTYPE html>
      <title>RequireJS Dojo</title>
      <script data-main="app" src="lib/require.js"></script>
      <h2>RequireJS  Dojo</h2>
         Hello... ...

Create a js file with the name app.js and add the following code in it −

require ({
   //You can configure loading modules from the lib directory
   baseUrl: 'lib',
   paths: {
      //mapping of package
      dojo: ''
}, [
      //modules which we are using here
   ], function(dom) { 
      //using the 'byId' method from dom module
      var mydojo = dom.byId('dojo_val')
      mydojo.innerHTML = "The text is displaying via dojo/dom";   


Open the HTML file in a browser; you will receive the following output −

RequireJS Dojo