With modern IDEs, it is possible for a developer to open a file by typing just a few characters of that file's name. This feature, along with a general desire to keep code organized, has motivated developers to separate their code into multiple files. In Backbone, this typically means creating one file for every Collection
, Model
, View
, and Router
, and even in a small project, this can add up to a lot of files.
All these files create two problems. First, each file needs to be downloaded separately, and as we learned in Chapter 8, Scaling Up: Ensuring Performance in Complex Applications, browsers can only download between 2 and 8 files at once. Second, the order in which files are loaded can become increasingly hard to manage, because of the dependencies among the different files (View A
needs Collection B
, which needs Model C
, which needs …). RequireJS (http://requirejs.org/) solves both of these problems.
RequireJS does this by organizing your code into...