User Interfaces (UI) are becoming increasingly popular, much like responsive web design. Extremely popular websites like Gmail, Facebook, and Twitter have adopted extremely responsive client-side applications.
Rarely do you see a full-page refresh; instead, the content is loaded inline. Most importantly, your context is maintained and you are not forced to jump around between multiple pages.
A perfect example of this is Gmail. Ironically, it came from writing this book. I was reviewing an email from my editor and technical reviewer. I had the email opened and wanted to respond to it. Because Gmail placed my reply inline, I could easily review the email and write my response at the same time—no need to jump around or have two windows open.
KnockoutJS made its debut back in July of 2010. It was released as an open source project by author Steve Sanderson. It is now being maintained by the open source community. Version 3.0 was released in late 2013.
It continues to evolves daily with new features, enhancements, and bug fixes. All of the examples in this book use version 3.2 (the stable release).
Setting up KnockoutJS is very simple. Begin by visiting the KnockoutJS downloads page.
You can download the minified version of Knockout by right-clicking (Ctrl+Click for Mac) and selecting the “Save link as...” option.
I suggest creating a new folder for all of the code examples in this book. Inside that folder, make a subfolder called js and place the knockout-3.2.0.js file inside.
It is quite normal for popular open source frameworks to evolve quite quickly. If the current version of Knockout is not 3.2 when you download it, the examples in this book should continue to work. However, you will need to update the following:
You will need to replace
<current-version> with the correct value.
If you want to use version 3.2 like the examples in this book, you can visit the KnockoutJS project on Github and grab your version of choice.
Once the Knockout framework is downloaded, create an HTML page that loads the framework, like in Example P-1.
In the example above, I included KnockoutJS just before the end
The following typographical conventions are used in this book:
Indicates new terms, URLs, email addresses, filenames, and file extensions.
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.
This element signifies a tip or suggestion.
This element signifies a general note.
This element indicates a warning or caution.
Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/oreillymedia/knockout_js.
This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Knockout.js by Jamie Munro (O’Reilly). Copyright 2015 Jamie Munro, 978-1-491-91431-1.”
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at firstname.lastname@example.org.
Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.
Members have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more information about Safari Books Online, please visit us online.
Please address comments and questions concerning this book to the publisher:
We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://bit.ly/knockoutjs-book.
To comment or ask technical questions about this book, send email to email@example.com.
For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
I must first thank my wife, Shannon. She helped immensely by being such a good mom to our three young children—Lily, Owen, and Kayla—while I was writing this book. Without her love and support, I would get no sleep at all!
Secondly, to Steve Kennedy (you may see his name pop up every now and then in examples). We spent many a lunch hour going over minute details of almost every aspect of the book. He made sure that every example was technically accurate and ensured the “why” was thoroughly covered. I hope the “why” things are done will be invaluable throughout this book.
Third, to Mike Wilson (best to not try the email address in Example 9-4!). Mike really helped shape the early chapters to ensure we got right to the examples before presenting the theory. As a reader of many books, this always makes me feel better to see the results of the “Hello World” example immediately.
I can’t forget the team at O’Reilly. Thanks to Meg, Kara, and Gillian for making this a wonderful experience.
And finally, to you, the reader: I hope you enjoy reading this book and learn as much as I did from writing it!