Periodic Refreshing for the Browser-Server Dialogue - Alternatives to Periodic Refresh
(Page 4 of 4 )
HTTP Streaming
One of the forces for this pattern is that HTTP connections tend to be short-lived. That's a tendency, not a requirement. As HTTP Streaming (Chapter 6) explains, there are some circumstances where it's actually feasible to leave the connection open. Streaming allows for a sequence of messages to be downloaded into the browser without the need for explicit polling. (Low-level polling still happens at the operating system and network levels, but that doesn't have to be handled by the web developer, and there's no overhead of starting and stopping an HTTP connection for each refresh, nor of starting and stopping the web service.)
Related Patterns
Distributed Events
You can use Distributed Events (see later in this chapter) to coordinate browser activity following a response.
Fat Client, Browser-Side Cache, Guesstimate
A little work on performance issues can help make the system feel more responsive. Some of the performance optimization patterns help:
Fat Client (Chapter 13)
Reduces the need for server processing by pushing functionality into the browser.
Browser-Side Cache (Chapter 13)
Reduces queries by retaining query data locally.
Guesstimate (Chapter 13)
Gives the user a sense of what's happening without actually performing any query.
Submission Throttling
Submission Throttling (see the next pattern) also involves a periodic call to the server. The emphasis there is on uploading browser-side changes, whereas the present pattern focuses on downloading server-side changes. The two may be combined to form a general-purpose "synchronize" operation, as long as the update frequency is sufficient in both directions. This would improve performance by reducing the amount of overall traffic. The Wiki Demo (http://ajaxify.com/run/wiki) takes this approach.
Heartbeat
It's inevitable that users will leave their browser pointing at web sites they're not actually using. The rising popularity of tabbed browsing--now supported by all the major browsers--only exacerbates the problem. You don't want to keep refreshing the page for idle users, so use Heartbeat (Chapter 17) to detect whether the user is still paying attention.
Metaphor
A movie is refreshed at subsecond intervals to provide the illusion of real-time activity.
Please check back next week for the continuation of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter 10 of the book Ajax Design Patterns, written by Michael Mahemoff (O'Reilly, 2006; ISBN: 0596101805). Check it out today at your favorite bookstore. Buy this book now.
|
|