javascript - understanding requirejs paths -
using requirejs main.js looks this
requirejs.config({ baseurl: '/javascript/', paths: { jquery: 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min', async: 'requireplugins/async', hbs: 'hbs' }, waitseconds: 7 }); define(['common'], function () { loadfonts(); }); the main.js included in page script call
<script data-main="/javascript/main.js" src="/javascript/require-2.0.1.js"></script> common basic function website, jquery doc ready function etc. wrapped in define call:
define(['jquery'], function() { //jquery dependant common code }); this works fine, jquery loaded google cdn , code executed. when add require call after load of main.js
<script data-main="/javascript/main.js" src="/javascript/require-2.0.1.js"></script> require(['jquery'], function ($) { //code }); jquery requested /javascript/jquery.js instead of defined path google cdn. i'm still rookie @ requirejs seem me path should defined before of other requests fired, can please me understand i'm doing wrong?
i think due using data-main attribute on requirejs script tag; parsed, requirejs has load , parse. in testing (specifically ie9), browser download , execute script tags directly following requirejs script tag before parsing requirejs config file (the 1 specified data-main attribute).
to around this, quit using data-main attribute , instead placed config file normal script tag directly after requirejs script tag, , seems happy now.
specifically, looks (using sample):
<script src="/javascript/require-2.0.1.js"></script> <script src="/javascript/main.js"></script>
Comments
Post a Comment