RequireJS
<script data-main="/js/app.js" src='/js/require.js'></script>
js/app.js
requirejs.config({ baseUrl: '/js/lib', paths: { app: '../app', "jquery-ui": 'jquery-ui/jquery-ui', jqplot: 'jqplot/jquery.jqplot.min', dateAxisRenderer: 'jqplot/plugins/jqplot.dateAxisRenderer' }, shim: { jqplot: { deps: ['jquery'], exports: 'jqplot' }, dateAxisRenderer: { deps: ['jquery', 'jqplot'], exports: 'dateAxisRenderer' } } }); requirejs([ 'jquery', 'app/cardbox', 'app/weightGraph', 'app/totalGraph' ], function ( $, cardbox, weightGraph, totalGraph ) { if ($(".datepicker").length > 0) { requirejs(['jquery-ui'], function (jqueryui) { $(".datepicker").datepicker({dateFormat: 'yy-mm-dd'}); }); } });
js/app/graph.js
define(['jquery'], function ($) { return { getData: function (url, plot, options) { var series; $.ajax({ async: false, url: url, dataType: "json", success: function (remoteData) { series = remoteData.series; } }); return series; } }; });