I have the website, which is use intranet (small share) as well as on the internet (larger share). Intranet environment, doesn't have internet access. I was planning to load JavaScript from CDN for internet users, while using a local version for intranet user. I am using RequireJS library to dynamically load the scripts, and use failover, when it can't retrieve from the CDN.
I am using the following requireJS configuration to load jQuery library from CDN or use the local one.
Problem occurs, when RequireJS fails to load from CDN, it loads the bootstrap library prior of loading of local version of jquery. This cause two error, 'Bootstrap requires jQuery' from bootstrap and timeout error from requireJS.
My question, how to I avoid this? I want bootstrap to wait till any (CDN or local) version of jQuery is loaded. I have use Shim to define bootstrap dependency on jQuery library. But, it didn't work as anticipated. Is this known bug in requireJS?
Here, my configuration code
require.config({
paths: {
jquery: ['https://code.jquery.com/jquery-1.10.2'
, '/Scripts/_Ref/jquery-1.10.2'],
async: '/Scripts/_Ref/async',
propertyParser: '/Scripts/_Ref/propertyParser',
goog: '/Scripts/_Ref/goog',
bootstrap: '/Scripts/_Ref/bootstrap'
},
shim: {
'bootstrap': {
deps: ['jquery']
}
}
});
require.onError = function (err) {
console.log('RSC JS Error: ' + err.requireType);
if (err.requireType === 'timeout') {
var errorMessage = 'Following modules timeout: ' + err.requireModules;
console.log(errorMessage);
MyNamespace.ShowErrorMessage(errorMessage);
}
};
To demonstrate the problem, I have create a sample website, where I have block the internet and stimulate failover to occur. Here, is the video link http://www.screencast.com/t/gcQ2I9aUdBY where I have shown problem in action