O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JavaScript Web Applications

Book Description

Building rich JavaScript applications that bring a desktop experience to the Web requires moving state from the server to the client side—not a simple task. This hands-on book takes proficient JavaScript developers through all the steps necessary to create state-of-the-art applications, including structure, templating, frameworks, communicating with the server, and many other issues.

Throughout the book, you'll work with real-world example applications to help you grasp the concepts involved. Learn how to create JavaScript applications that offer a more responsive and improved experience.

  • Use the Model-View-Controller (MVC) pattern, and learn how to manage dependencies inside your application
  • Get an introduction to templating and data binding
  • Learn about loading remote data, Ajax, and cross-domain requests
  • Create realtime applications with WebSockets and Node.js
  • Accept dropped files and upload data with progress indicators
  • Use major frameworks and libraries, including jQuery, Spine, and Backbone
  • Write tests and use the console to debug your applications
  • Get deployment best practices, such as caching and minification

Table of Contents

  1. Preface
    1. Who Is This Book For?
    2. How This Book Is Organized
    3. Conventions Used in This Book
    4. Accompanying Files
    5. Code Conventions
      1. jQuery Examples
    6. Holla
    7. Author’s Note
    8. Safari® Books Online
    9. How to Contact Us
  2. 1. MVC and Classes
    1. Early Days
    2. Adding Structure
    3. What Is MVC?
      1. The Model
      2. The View
      3. The Controller
    4. Toward Modularity, Creating Classes
    5. Adding Functions to Classes
    6. Adding Methods to Our Class Library
    7. Class Inheritance Using Prototype
    8. Adding Inheritance to Our Class Library
    9. Function Invocation
    10. Controlling Scope in Our Class Library
    11. Adding Private Functions
    12. Class Libraries
  3. 2. Events and Observing
    1. Listening to Events
    2. Event Ordering
    3. Canceling Events
    4. The Event Object
    5. Event Libraries
    6. Context Change
    7. Delegating Events
    8. Custom Events
    9. Custom Events and jQuery Plug-Ins
    10. Non-DOM Events
  4. 3. Models and Data
    1. MVC and Namespacing
    2. Building an ORM
      1. Prototypal Inheritance
      2. Adding ORM Properties
      3. Persisting Records
    3. Adding ID Support
    4. Addressing References
    5. Loading in Data
      1. Including Data Inline
      2. Loading Data with Ajax
      3. JSONP
      4. Security with Cross-Domain Requests
    6. Populating Our ORM
    7. Storing Data Locally
    8. Adding Local Storage to Our ORM
    9. Submitting New Records to the Server
  5. 4. Controllers and State
    1. Module Pattern
      1. Global Import
      2. Global Export
    2. Adding a Bit of Context
      1. Abstracting into a Library
      2. Loading Controllers After the Document
      3. Accessing Views
      4. Delegating Events
    3. State Machines
    4. Routing
      1. Using the URL’s Hash
      2. Detecting Hash Changes
      3. Ajax Crawling
      4. Using the HTML5 History API
  6. 5. Views and Templating
    1. Dynamically Rendering Views
    2. Templates
      1. Template Helpers
      2. Template Storage
    3. Binding
      1. Binding Up Models
  7. 6. Dependency Management
    1. CommonJS
      1. Declaring a Module
      2. Modules and the Browser
    2. Module Loaders
      1. Yabble
      2. RequireJS
    3. Wrapping Up Modules
    4. Module Alternatives
      1. LABjs
    5. FUBCs
  8. 7. Working with Files
    1. Browser Support
    2. Getting Information About Files
    3. File Inputs
    4. Drag and Drop
      1. Dragging
      2. Dropping
      3. Cancel Default Drag/Drop
    5. Copy and Paste
      1. Copying
      2. Pasting
    6. Reading Files
      1. Blobs and Slices
    7. Custom Browse Buttons
    8. Uploading Files
      1. Ajax Progress
    9. jQuery Drag and Drop Uploader
      1. Creating a Drop Area
      2. Uploading the File
  9. 8. The Real-Time Web
    1. Real Time’s History
    2. WebSockets
      1. Node.js and Socket.IO
    3. Real-Time Architecture
    4. Perceived Speed
  10. 9. Testing and Debugging
    1. Unit Testing
      1. Assertions
      2. QUnit
      3. Jasmine
    2. Drivers
    3. Headless Testing
      1. Zombie
      2. Ichabod
    4. Distributed Testing
    5. Providing Support
    6. Inspectors
      1. Web Inspector
      2. Firebug
    7. The Console
      1. Console Helpers
    8. Using the Debugger
    9. Analyzing Network Requests
    10. Profile and Timing
  11. 10. Deploying
    1. Performance
    2. Caching
    3. Minification
    4. Gzip Compression
    5. Using a CDN
    6. Auditors
    7. Resources
  12. 11. The Spine Library
    1. Setup
    2. Classes
      1. Instantiation
      2. Extending Classes
      3. Context
    3. Events
    4. Models
      1. Fetching Records
      2. Model Events
      3. Validation
      4. Persistence
    5. Controllers
      1. Elements
      2. Delegating Events
      3. Controller Events
      4. Global Events
      5. The Render Pattern
      6. The Element Pattern
    6. Building a Contacts Manager
      1. Contact Model
      2. Sidebar Controller
      3. Contacts Controller
      4. App Controller
  13. 12. The Backbone Library
    1. Models
      1. Models and Attributes
    2. Collections
      1. Controlling a Collection’s Order
    3. Views
      1. Rendering Views
      2. Delegating Events
      3. Binding and Context
    4. Controllers
    5. Syncing with the Server
      1. Populating Collections
      2. On the Server Side
      3. Custom Behavior
    6. Building a To-Do List
  14. 13. EmberJS
    1. The Application
    2. Models
      1. The Store
      2. The Adapter
      3. Defining Models
      4. Defining Relationships
    3. Templates
      1. Built-in Helpers
      2. Custom Helpers
    4. Controllers
      1. Responding to Actions
      2. Model Controllers
      3. Array Controllers
    5. Router
      1. Defining Routes
      2. Resource Routes
      3. Dynamic Segments
      4. Changing Routes
    6. Building a To-Do List
  15. A. jQuery Primer
    1. DOM Traversal
    2. DOM Manipulation
    3. Events
    4. Ajax
    5. Being a Good Citizen
    6. Extensions
    7. Creating a Growl jQuery Plug-in
  16. B. CSS Extensions
    1. Variables
    2. Mixins
    3. Nested Rules
    4. Including Other Stylesheets
    5. Colors
    6. How Do I Use Less?
      1. Via the Command Line
      2. Via Rack
      3. Via JavaScript
      4. Less.app
  17. C. CSS3 Reference
    1. Prefixes
    2. Colors
    3. Rounded Corners
    4. Drop Shadows
    5. Text Shadow
    6. Gradients
    7. Multiple Backgrounds
    8. Selectors
      1. Nth Child
      2. Direct Descendants
      3. Selector Negation
    9. Transitions
    10. Border Images
    11. Box Sizing
    12. Transformations
    13. Flexible Box Model
    14. Fonts
    15. Graceful Degradation
      1. Modernizr
      2. Google Chrome Frame
    16. Creating a Layout
  18. Index
  19. About the Author
  20. Colophon
  21. Copyright