Skip to main content
Post Made Community Wiki by Paul Sweatte
Source Link

Use a formal convention such as require.js. For example, to load jquery-ui:

requirejs.config({
    baseUrl: 'js/lib',
    paths: {
        // the left side is the module ID,
        // the right side is the path to
        // the jQuery UI file, relative to baseUrl.
        // Also, the path should NOT include
        // the '.js' file extension. This example
        // is using jQuery UI located at
        // js/lib/jquery-ui, relative to
        // the HTML page.
        jquery-ui: 'jquery-ui',
        jquery-ui-autocomplete: 'jquery-ui-autocomplete'
    }
});

and later on using the autocomplete plugin:

require([ "jquery-ui-autocomplete" ], function( autocomplete ) {
    autocomplete({ source: [ "One", "Two", "Three" ] }, "<input>" )
        .element
        .appendTo( "body" );
});

References