Preface - Developing Backbone.js Applications (2013)

Developing Backbone.js Applications (2013)

Preface

Not so long ago, data-rich web application was an oxymoron. Today, these applications are everywhere, and you need to know how to build them.

Traditionally, web applications left the heavy lifting of data to servers that pushed HTML to the browser in complete page loads. The use of client-side JavaScript was limited to improving the user experience. Now this relationship has been inverted—client applications pull raw data from the server and render it into the browser when and where it is needed.

Think of the Ajax shopping cart, which doesn’t require a refresh on the page when you add an item to your basket. Initially, jQuery was the go-to library for this paradigm. Its nature was to make Ajax requests, then update text on the page and so on. However, this pattern with jQuery revealed that we have implicit model data on the client side.

The rise of arbitrary code on the client side that can talk to the server however it sees fit has meant an increase in client-side complexity. Good architecture on the client side has gone from an afterthought to essential—you can’t just hack together some jQuery code and expect it to scale as your application grows. Most likely, you would end up with a nightmarish tangle of UI callbacks entwined with business logic, destined to be discarded by the poor soul who inherits your code.

Thankfully, there are a growing number of JavaScript libraries that can help improve the structure and maintainability of your code, making it easier for you to build ambitious interfaces without a great deal of effort. Backbone.js has quickly become one of the most popular open source solutions to these issues, and in this book I will walk you through it in depth.

We’ll begin with the fundamentals, work our way through the exercises, and learn how to build an application that is both cleanly organized and maintainable. If you are a developer looking to write code that can be more easily read, structured, and extended, this guide can help you.

Improving developer education is important to me, which is why this book is released under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license. This means you can purchase or grab a copy of the book for free or help to further improve it. Corrections to existing material are always welcome, and I hope that together we can provide the community with an up-to-date resource that is of help.

My extended thanks go out to Jeremy Ashkenas and DocumentCloud for creating Backbone.js and several members of the community for their assistance making this project far better than I could have imagined.

Target Audience

This book is targeted at novice to intermediate developers wishing to learn how to better structure their client-side code. An understanding of JavaScript fundamentals is required to get the most out of it; however, I have tried to provide a basic description of these concepts where possible.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

TIP

This icon signifies a tip, suggestion, or general note.

CAUTION

This icon indicates a warning or caution.