I'm using RequireJS to load dependencies. This is how my config looks like:
'use strict';
require.config({
paths: {
jQuery: 'http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min',
underscore: 'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min',
backbone: 'http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min'
}
shim: {
jQuery: {
exports: '$'
},
underscore: {
exports: '_'
},
backbone: {
deps: [
'underscore',
'jQuery'
],
exports: 'Backbone'
}
}
});
When I run my static website, in the console there are messages like this:
GET http://*myhost*/js/backbone.js 404 (Not Found) require.js:1896
Uncaught Error: Script error for: backbone
http://requirejs.org/docs/errors.html#scripterror require.js:166
GET http://*myhost*/js/jQuery.js 404 (Not Found) require.js:1896
Uncaught Error: Script error for: jQuery
http://requirejs.org/docs/errors.html#scripterror require.js:166
GET http://*myhost*/js/underscore.js 404 (Not Found) require.js:1896
Uncaught Error: Script error for: underscore
http://requirejs.org/docs/errors.html#scripterror require.js:166
Uncaught ReferenceError: jQuery is not defined
As you can see, RequireJS ignores the fact that I'm providing URLs for CND and tries to look for modules locally.
However, sometimes RequireJS works fine - it loads modules from URLs. Some kind of lottery over there. Worth to mention that it happens only on my remote development server - that is when I access my website over web. When I run my website locally, RequireJS always loads modules from CDN perfectly fine. Weird, any ideas why this is happening?
UPDATE
This is how I start my application:
<script type=text/javascript data-main=js/main src=js/require.js></script>
main.js (where config is loaded)
define(['config', 'router'], function(Config, Router) {
var router = new Router();
Backbone.history.start();
});