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

Best practices for working with routers

Working with a Backbone router is fairly easy when the application is of a small size. However, as the complexity increases, maintaining a router becomes difficult unless some rules are followed. In the following section, we will discuss some points that you should take care of while using routers.

Avoiding large functional code in route methods

Though the basic task of a router is to monitor the routes and trigger functions, it manages some business logics of the app too. In an MVC architecture, the task of a controller is to handle the data request that is sent from the client and work upon the data that comes from the server in response. Similarly for a router, since the URL fragments reflect some part of the application's data, the data communication, calling view methods, or updating model attributes are done using router methods.

A trend I often see in beginner-level developer code is that they frequently include a large chunk of functional code...