Created
February 27, 2013 15:15
-
-
Save basememara/5048648 to your computer and use it in GitHub Desktop.
RequireJS: Avoid double jQuery load and version conflict in main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function () { | |
var paths = { ... }; | |
//HANDLE JQUERY IF LOADED ALREADY TO AVOID OVERWRITING EXISTING JQUERY PROPERTIES AND PLUGINS | |
//CHECK FOR OLD VERSIONS OF JQUERY | |
var oldjQuery = !!(window.jQuery && !!window.jQuery.fn.jquery.match(/^1\.[0-4]/)); | |
//LOAD JQUERY IF NOT AVAILABLE OR BELOW MIN | |
if (!window.jQuery || oldjQuery) { | |
paths.jquery = [ | |
'//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min', | |
//If the CDN location fails, load from this location | |
'libs/jquery/jquery.min' | |
]; | |
} else { | |
//REGISTER THE CURRENT JQUERY | |
define('jquery', [], function () { return window.jQuery; }); | |
} | |
//CONFIGURE REQUIRE JS | |
require.config({ | |
... | |
paths: paths, | |
... | |
}); | |
//START REQUIRE JS | |
require([ | |
'jquery', | |
'app' | |
], function ($, App) { | |
//HANDLE MULTIPLE JQUERY VERSIONS IF NECESSARY | |
if (oldjQuery) $.noConflict(true); | |
//INITIALIZE APP | |
App.init(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment