Book Image

Backbone.js Patterns and Best Practices

By : Swarnendu De
Book Image

Backbone.js Patterns and Best Practices

By: Swarnendu De

Overview of this book

Table of Contents (19 chapters)
Backbone.js Patterns and Best Practices
About the Author
About the Reviewers
Precompiling Templates on the Server Side

Working with Asynchronous Module Definition

So far, we have learned to add all our script files in HTML files within SCRIPT tags. The browser loads these files synchronously and hence we always need to ensure that if one file has a dependency over another file, the latter should always be loaded prior to the former. Since all of the references to these dependencies are made via global variables, these dependencies must be loaded in the proper order, and a developer must take care of them before he adds a new script file to the application. Although this process works just fine, it may become difficult to manage large applications as too many dependencies will overlap. AMD provides a solution to this problem.

AMD is a mechanism used to define a module such that the module and its dependencies can be asynchronously loaded. So, multiple AMD modules can be loaded in parallel, and once the last dependent module is loaded, the main module will execute. In addition, AMD omits the use of global variables...