You are previewing Data Push Apps with HTML5 SSE.
O'Reilly logo
Data Push Apps with HTML5 SSE

Book Description

Make sure your website or web application users get content updates right now with minimal latency. This concise guide shows you how to push new data from the server to clients with HTML5 Server-Sent Events (SSE), an exceptional technology that doesn’t require constant polling or user interaction. You’ll learn how to build a real-world SSE application from start to finish that solves a demanding domain problem.

Table of Contents

  1. Preface
    1. The Kind of Person You Need to Be
    2. Organization of This Book
    3. Conventions Used in This Book
    4. Using Code Examples
    5. Safari® Books Online
    6. How to Contact Us
  2. 1. All About SSE...And Then Some
    1. HTML5
    2. Data Push
    3. Other Names for Data Push
    4. Potential Applications
    5. Comparison with WebSockets
    6. When Data Push Is the Wrong Choice
    7. Decisions, Decisions…
    8. Take Me to Your Code!
  3. 2. Super Simple Easy SSE
    1. Minimal Example: The Frontend
    2. Using JQuery?
    3. Minimal Example: The Backend
    4. The Backend in Node.js
      1. Minimal Web Server in Node.js
      2. Pushing SSE in Node.js
      3. Now to Get It Working in a Browser!
    5. Smart, Sassy Exit
  4. 3. A Delightfully Realistic Data Push Application
    1. Our Problem Domain
    2. The Backend
    3. The Frontend
    4. Realistic, Repeatable, Random Data
    5. Fine-Grained Timestamps
    6. Taking Control of the Randomness
    7. Making Allowance for the Real Passage of Time
    8. Taking Stock
  5. 4. Living in More Than the Present Moment
    1. More Structure in Our Data
    2. Refactoring the PHP
    3. Refactoring the JavaScript
    4. Adding a History Store
    5. Persistent Storage
    6. Now We Are Historians…
  6. 5. No More Ivory Tower: Making Our Application Production-Quality
    1. Error Handling
    2. Bad JSON
    3. Adding Keep-Alive
      1. Server Side
      2. Client Side
      3. SSE Retry
    4. Adding Scheduled Shutdowns/Reconnects
    5. Sending Last-Event-ID
    6. ID for Multiple Feeds
    7. Using Last-Event-ID
    8. Passing the ID at Reconnection Time
    9. Don’t Act Globally, Think Locally
    10. Cache Prevention
    11. Death Prevention
    12. The Easy Way to Lose Weight
    13. Looking Back
  7. 6. Fallbacks: Data Push for Everyone Else
    1. Browser Wars
    2. What Is Polling?
    3. How Does Long-Polling Work?
    4. Show Me Some Code!
    5. Optimizing Long-Poll
    6. What If JavaScript Is Disabled?
    7. Grafting Long-Poll onto Our FX Application
      1. Connecting
      2. Long-Poll and Keep-Alive
      3. Long-Poll and Connection Errors
      4. Server Side
      5. Dealing with Data
      6. Wire It Up!
      7. IE8 and Earlier
      8. IE7 and Earlier
    8. The Long and Winding Poll
  8. 7. Fallbacks: There Has to Be a Better Way!
    1. Commonalities
    2. XHR
    3. iframe
    4. Grafting XHR/Iframe onto Our FX Application
      1. XHR on the Backend
      2. XHR on the Frontend
      3. Iframe on the Frontend
      4. Wiring Up XHR
      5. Wiring Up Iframe
    5. Thanks for the Memories
    6. Putting the FX Baby to Bed
  9. 8. More SSE: The Rest of the Standard
    1. Headers
    2. Event
    3. Multiline Data
    4. Whitespace in Messages
    5. Headers Again
    6. So Is That Everything?
  10. 9. Authorization: Who’s That Knocking at My Door?
    1. Cookies
    2. Authorization (with Apache)
    3. HTTP POST with SSE
    4. Multiple Authentication Choices
    5. SSL and CORS (Connecting to Other Servers)
    6. Allow-Origin
    7. Fine Access Control
    8. HEAD and OPTIONS
    9. Chrome and Safari and CORS
    10. Constructors and Credentials
    11. withCredentials
    12. CORS and Fallbacks
      1. CORS and IE9 and Earlier
      2. IE8/IE9: Always Use Long-Poll
      3. Handling IE9 and Earlier Dynamically
    13. Putting It All Together
    14. The Future Holds More of the Same
  11. A. The SSE Standard
    1. W3C Candidate Recommendation 11 December 2012
      1. Abstract
      2. Status of This Document
        1. Candidate Recommendation Exit Criteria
      3. Table of Contents
      4. 1 Introduction
      5. 2 Conformance requirements
        1. 2.1 Dependencies
      6. 3 Terminology
      7. 4 The EventSource interface
      8. 5 Processing model
      9. 6 Parsing an event stream
      10. 7 Interpreting an event stream
      11. 8 Notes
      12. 9 Connectionless push and other features
      13. 10 Garbage collection
      14. 11 IANA considerations
        1. 11.1 <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">text/event-stream</code>
        2. 11.2 <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">Last-Event-ID</code>
      15. References
      16. Acknowledgements
  12. B. Refactor: JavaScript Globals, Objects, and Closures
    1. Introducing the Example
    2. The Problem Is…
    3. JavaScript Objects and Constructors
    4. The Code with Objects
    5. JavaScript Closures
    6. Tea for Two, and Two for Tea
  13. C. PHP
    1. Classes in PHP
    2. Random Functions
    3. Superglobals
    4. Date Handling
    5. Passwords
    6. Falling Asleep
  14. Index
  15. Colophon
  16. Copyright