RequireJS allows you to create expendable JQuery / AngularJS (AMD) applications without worrying about version conflicts
Instead of worrying about noconflict's library, RequireJS creates a separate area with a sandbox / variable outside the global with AMD . Only included versions are available in AMD .
AMD - Asynchronous module definitions are self-nesting applications with their own area for libraries. Self-Encolsure is similar to a namespace, complete absence of conflicts. For more information about using modules, see WHY WEB MODULES .
AngularJS example, create an AngularMain.js file:
require.config({ baseUrl: "js", paths: { 'angular': '//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min', 'angularAMD': 'lib/angularAMD.min', 'ngload': 'lib/ngload.min' }, shim: { 'angularAMD': ['angular'], 'angular-route': ['angular'] }, deps: ['AngularApp'] });
Now require.config indicated that AngularApp.js should also be included (as you will see, RequireJS usually assumes the ".js" extensions), with dependencies on angular.js and angular -route.js
Now you define your Angular application and controllers using the combination of RequireJS and AngularJS syntax in the AngularApp.js file:
define(['angularAMD', 'angular-route'], function (angularAMD) { var app = angular.module("webapp", ['ngRoute']); app.config(function ($routeProvider) { $routeProvider.when("/home", angularAMD.route({ templateUrl: 'views/home.html', controller: 'HomeCtrl', controllerUrl: 'ctrl/home' })) }); return angularAMD.bootstrap(app); }); define(['app'], function (app) { app.controller('HomeCtrl', function ($scope) { $scope.message = "Message from HomeCtrl"; }); });
Finally: your HTML page requests application links with a link to require.js and a data-main attribute indicating the application file.
<script data-main="js/AngularMain" src=".../require.js"></script>
Once again: the .js file extension is optional