All Projects → johnpapa → Kis Requirejs Demo

johnpapa / Kis Requirejs Demo

Keep It Simple RequireJS Demo. Shows simple demo of require.js before and after

Programming Languages

javascript
184084 projects - #8 most used programming language

kis-requirejs-demo

Keep It Simple RequireJS Demo. Shows simple demo of how to use require.js.

##Overview This demo contains 2 separate html files, each with their own scripts folder. One example demonstrates how to write the code without require.js. The other shows how to add require.js. The purpose is to explain how to use require.js for dependency resolution.

##Without RequireJS The first example (index1.html) has 3 JavaScript files using the Revealing Module Pattern (Module Pattern works fine too). The dependencies are as follows:

  • main.js depends on alerter.js
  • alerter.js depends on daataservice.js

Load order is important here, and can easily be broken.

##With RequireJS The second example (index2.html) uses require.js to load the scripts. It solves the problem and has these roles:

  • starts with a kickoff script (main.js)
  • loads therest of the scripts as they are needed (when dependencies call on them)

##With RequireJS and 3rd Party Dependencies The third example (index3.html) uses require.js to load the scripts while jquery is also introduced as a dependency.

##More Related topics: Dependency Injection (DI), Revealing Module Pattern, Module Pattern, Immediately Invoked Function Execution (IIFE), and Service Locator Pattern

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].