I\'m using require.js (http://requirejs.org/) for a number of functions on my site and so far it seems to be working well. I\'ve run into an issue when trying to include Google
None of the other answers worked for me, but I managed to figure out something that does work, after reading the Google Analytics documentation.
in your main app.js
requirejs.config({
paths: {
ga: '//www.google-analytics.com/analytics'
}
});
requirejs(['analytics'], function () {
...
});
in its own file analytics.js:
define(['ga'], function () {
window.ga('create', 'UA-XXXXXX-1');
window.ga('send', 'pageview');
});
This works because requirejs guarantees that by the time the function executes, analytics.js will have finished loading. This means that the window.ga function is ready to accept commands.