MANNING Michael S. Mikowski Josh C. Powell FOREWORD BY Gregory D. Benson JavaScript end-to-end www.it-ebooks.info Single Page Web Applications www.it-ebooks.info www.it-ebooks.info Single Page Web Applications J AVA S CRIPT END - TO - END MICHAEL S. MIKOWSKI JOSH C. POWELL MANNING Shelter Island www.it-ebooks.info For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2014 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editor: Karen Miller 20 Baldwin Road Technical proofreader: John J. Ryan III Shelter Island, NY 11964 Production editor: Janet Vail Copyeditor: Benjamin Berg Proofreader: Toma Mulligan Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN 9781617290756 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 18 17 16 15 14 13 www.it-ebooks.info To my parents, wife, and children. You have taught me so much, and I love you all. —M.S.M. To my wife, Marianne. Thank you for your extraordinary patience with all the time I took writing the book. I love you. —J.C.P. www.it-ebooks.info www.it-ebooks.info vii brief contents P ART 1 I NTRODUCING SPA S . 1 1 ■ Our first single page application 3 2 ■ Reintroducing JavaScript 23 P ART 2 T HE SPA CLIENT 59 3 ■ Develop the Shell 61 4 ■ Add feature modules 95 5 ■ Build the Model 139 6 ■ Finish the Model and Data modules 178 P ART 3 T HE SPA SERVER 227 7 ■ The web server 229 8 ■ The server database 265 9 ■ Readying our SPA for production 313 www.it-ebooks.info www.it-ebooks.info ix contents foreword xv preface xvii acknowledgments xviii about this book xx about the cover illlustration xxiv P ART 1 I NTRODUCING SPA S 1 1 Our first single page application 3 1.1 Definition, a little history, and some focus 4 A little history 4 ■ What took JavaScript SPAs so long? 5 Our focus 8 1.2 Build our first SPA 9 Define the goal 9 ■ Start the file structure 10 ■ Set up Chrome Developer Tools 10 ■ Develop the HTML and CSS 11 ■ Add the JavaScript 12 ■ Inspect our application using Chrome Developer Tools 17 1.3 The user benefits of a well-written SPA 20 1.4 Summary 21 www.it-ebooks.info [...]... www.ubuntu.com/download/server) Author Online Purchase of Single Page Web Applications includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and from other users To access the forum and subscribe to it, point your web browser to www.manning.com/ SinglePageWebApplications This page provides information on how... success of commercial and enterprise web applications SPAs are often the best choice to provide the optimal user experience As a result, we expect the demand for user-focused design to drive SPA adoption and sophistication www.it-ebooks.info Our first single page application This chapter covers ■ Defining single page web applications ■ Comparing the most popular single page application platforms—Java,... web since IE 6 was the good browser A software engineer and web architect with over 13 years of experience, he loves the craft of developing web applications and building teams to do the same He’s currently immersed in playing with different single page web application technologies and loving every minute of it By some quirk of nature, he’s energized by public speaking and has presented on single page. .. together And we expect this stack will continue to gain popularity and become one of the most commonly used stacks for single page applications Roadmap Chapter 1 is an introduction to Single Page Applications JavaScript SPAs are defined and compared to other kinds of SPAs Traditional web sites and SPAs are compared, and the opportunities, benefits, and challenges of using an SPA are discussed The reader... and Javascript ■ Writing our first JavaScript single page application ■ Inspecting the application using Chrome Developer Tools ■ Exploring the user benefits of single page applications This book is intended for web developers, architects, and product managers with at least a smattering of JavaScript, HTML, and CSS experience If you’ve never even dabbled in web development, this book is not for you, although... Many books are available that do a great job teaching beginner website development and design, but this isn’t one of them This book does aspire to be a great guide to designing and building large-scale single page web applications [SPAs] using JavaScript end to end In fact, as figure 1.1 3 www.it-ebooks.info 4 CHAPTER 1 Our first single page application Database Server Client JavaScript JavaScript JavaScript... of the page becomes functional For example, sometimes a link can be clicked as soon as it appears on a web page; other times we have to wait until the redrawing is 100% complete plus five seconds This slow, inconsistent, and clunky experience is becoming unacceptable for an increasingly sophisticated web consumer Prepare to learn about another—and dare we say better—approach to developing web applications, ... If you’ve never even dabbled in web development, this book is not for you, although you’re welcome to buy it anyway (go ahead, daddy needs a new car) Many books are available that do a great job teaching beginner website development and design, but this isn’t one of them This book does aspire to be a great guide to designing and building large-scale Single Page Web Applications (SPAs) using JavaScript... we got along really well and had some interesting discussions about single page web applications (SPAs) and the future of the internet One day, Josh naively suggested we write a book together I foolishly agreed, and we sealed our collective fates for hundreds of weekends to come We expected this would be a rather slim book, under 300 pages The idea was to provide an over-the-shoulder view of an experienced... developing web applications, the single page web application (SPA) An SPA delivers a desktop application in the browser The result is a highly responsive experience that surprises and delights users instead of confusing and annoying them In part 1 we learn: ■ ■ What an SPA is and the advantages it provides over traditional websites How an SPA approach can make our web application a great deal more . Gregory D. Benson JavaScript end-to-end www.it-ebooks.info Single Page Web Applications www.it-ebooks.info www.it-ebooks.info Single Page Web Applications J AVA S CRIPT END - TO - END MICHAEL S me a web architect position in the summer of 2011. Though I ultimately decided to take another offer, we got along really well and had some interesting discussions about single page web applications ( SPA s). 392 B.6 Summary 395 index 397 www.it-ebooks.info xv foreword I wrote my first JavaScript single page web application ( SPA ) in 2006, although we didn’t call it that at the time. This was quite