Backbone is an amazing library to build web applications; it's small, simple, and yet powerful. It provides a set of small and focused objects to be used as bricks when building frontend applications.
The beauty of Backbone is that it gives you the freedom to build your applications with your rules. However, with great power comes great responsibility; Backbone does not tell you anything about how to structure your applications. Keep in mind that Backbone is not a framework but a library.
After years of working with Backbone projects, making code experiments, and exploring code from other developers, I have identified patterns and best practices when building frontend web apps with Backbone.
This book explains how to give structure to your applications. It gives you the tools and strategies to create robust and maintainable web apps. It will help you define and assign the right responsibilities to the Backbone objects and define a new set of glue objects.
In the book, you will build a functional application applying the concepts that are exposed here. The application is simple enough to put in to practice the core concepts when building scalable frontend applications with Backbone. At any time, you can see the project code in the book repository at https://github.com/abiee/mastering-backbone.
Chapter 1, Architecture of a Backbone application, deals with the project organization at two levels: logical and physical. On the logical side, you will learn how to connect the Backbone objects, while on the physical side, you will see where to put your scripts.
Chapter 2, Managing views, helps you extract the common patterns of views and create a new set of general purpose views that can be used on any Backbone application. These views will remove a lot of boilerplate code when managing views.
Chapter 3, Model bindings, explains how to deal with complex REST resources and helps you handle embedded resources and keep it in sync with views.
Chapter 5, Dealing with files, it covers the common requirement for web applications to upload files to a server, this chapter tells you how to do it in Backbone with a REST server.
Chapter 6, Store data in the browser, shows you how to store data in the browser and how to do it from a Backbone perspective. The chapter shows how to build two drivers to transparently store Backbone models in localStorage and indexedDB instead of a remote server. This can be useful if you want to create offline applications.
Chapter 7, Build like a pro, tells you how you can automatize common and repetitive tasks in a script. It will dramatically improve your productivity. It describes how you can build a development workflow that automatically refreshes your project every time you make a small change.
Chapter 8, Testing Backbone applications, shows you the strategies and best practices when testing frontend code.
Chapter 9, Deploy to production, shows you how to deploy the project to a production server. While high-demand applications need a sophisticated platform, this chapter gives you the starting point for small apps.
Chapter 10, Security, teaches you how to authenticate against the REST servers and how to manage sessions from the Backbone side.
Though this book is for frontend applications, you will need to install Node version 5 or superior. Node will run the example REST server, automatize common tasks, and manage project dependencies.
This book is made for developers who already know Backbone but want to create better projects; it does not explain Backbone from scratch. Instead, I will show you how to improve your skills to organize and structure your application in an effective way.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the
A block of code is set as follows:
[default] exten => s,1,Dial(Zap/1|30) exten => s,2,Voicemail(u100) exten => s,102,Voicemail(b100) exten => i,1,Voicemail(s0)
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
exten => s,1,Dial(Zap/1|30)
exten => s,2,Voicemail(u100)
exten => s,102,Voicemail(b100)
exten => i,1,Voicemail(s0)
Any command-line input or output is written as follows:
# cp /usr/src/asterisk-addons/configs/cdr_mysql.conf.sample /etc/asterisk/cdr_mysql.conf
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves you to the next screen."
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail
<[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at
<[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at
<[email protected]>, and we will do our best to address the problem.