Question: Locally the app works great, once it is on a server about 50% of the time the jquery libraries aren't loading fast enough and the app throws a bunch of undefined js errors for anything jquery related. I am using backbone.js with jquery, jquery mobile, jquery ui, and required.js. Does the require js file look correct, or is there a way to tell if the scripts have loaded before starting the app?

```
require.config({

paths: {
    jquery: 'libs/jquery/jquery-1.7.2',
'jquery.ui':'libs/jquery-ui/jquery-ui-1.8.14.custom',
    'jquery.mobile-config': 'libs/jqm/jquery.mobile-config',
    'jquery.mobile': 'libs/jqm/jquery.mobile-1.1.1',
    underscore: 'libs/underscore/underscore-1.3.3',
    backbone: 'libs/backbone/backbone-amd-0.9.2',
text: 'libs/require/text',
    templates: '../templates'
},

shim: {
    'underscore': {
        exports: "_"
    },
    'backbone': {
        deps: ['jquery','underscore'],
        exports: 'Backbone'
    },
    'jquery.ui': {
        deps:['jquery']
    },
    'jquery.mobile-config': {
        deps: ['jquery']
    },
    'jquery.mobile': {
        deps:['jquery','jquery.mobile-config']
    },
    'bundles': {
        deps:['jquery','jquery.mobile','validate','jquery.ui']
    },
},

waitSeconds: 5

});

require([
    'app'
], function(App) {
    $(function() {
        clearInitialLoader();
        App.initialize();
    });
});

```

Answer: 
So, in a live site it's pretty much a given you should be stitching and minifying your resources. There are too many resources in an AMD setup to actually try to download them all on-demand in a live site. AMD modules are a development-time convenience, not a deployment solution.

As far as module order, I never had any luck using the exports. The best best, we found, is to wrap the external dependencies in an AMD wrapper. Yes, this means you'll need to re-do it if you update the external library, but it's actually not as big of a deal as you might think.

First you wrap the library

```
//underscore.js file
define(function(){
  //underscore code
  return underscore
})

```

Then you can include it anywhere, and get all the benefits of order-guaranteed AMD loading:

```
//backbone.js (or any other file that wants underscore)
define([underscore],function(_){
  //backbone code
  return Backbone
})

```
You should take a look at the [shim options](http://requirejs.org/docs/api.html#config-shim) allowing you to load modules in order.

Also you could use [require.js optimizer](http://requirejs.org/docs/optimization.html) to concatenate all your files into one.