I saw lot posts and articles in this area. Some of them are,
Developing Modular Backbonejs Applications
TodoMVC with requireJS
Stack Overflow post with most upvotes
So no problem for me to modularize jquery, backbonejs and other libraries. My questions is why should i do it? Because on each js file we are going to use jquery and backbonejs and adding this below code on each file seems extra burden to me.
define([
'jquery',
'underscore',
'backbone',
'myFile1', 'myFile1'
], function ($, _, Backbone, module1, module2) {
Why should i not include them directly into html file before including requireJS like below?
<script src="../lib/client/jquery.js"></script>
<script src="../lib/client/underscore.js"></script>
<script src="../lib/client/backbone.js"></script>
<script data-main="client/main" src="../lib/client/require.js"></script>
In this case, i don't need to define jquery or backbonejs on every js file. I can modularize my own js files alone, like below.
define([
'myFile1', 'myFile1'
], function (module1, module2) {
What are the disadvantage by this method? Is this right approach? Did i break any requirejs rules?