Reverse Ajax

Reverse Ajax is the biggest new feature in DWR 2.0. It gives you the ability to asynchronously send data from a web-server to a browser.

The web was not designed to allow web servers to make connections to web browsers, so it can be tricky to get data to a browser in a timely manner. DWR supports 3 methods of pushing the data from to the browser: Piggyback, Polling and Comet.


Polling is the most obvious solution to the problem. This is where the browser makes a request of the server at regular and frequent intervals, say every 3 seconds, to see if there has been an update to the page. It's like a 5 year old in the back of the car shouting 'are we there yet?' every few seconds.


Comet (AKA long lived http, server push) allows the server to start answering the browser's request for information very slowly, and to continue answering on a schedule dictated by the server. For more information about Comet, see the following:


With the piggyback option, the server, having an update to send, waits for the next time the browser makes a connection and then sends it's update along with the response that the browser was expecting.


Each method has some benefits. Polling is simple to implement, however it can easily overload a server. In contrast Comet is a huge hack, but is much easier on servers. Comet also scores by having very low latency - there is no need to wait for the next time the browser connects. Both polling and comet require extra network connectivity, so the really low overhead version is piggyback, but that can be very high latency.

The good news is that DWR allows you to use all three, with only configuration changes to switch implementation.

Since Comet connections almost never last forever; for various reasons it is common to reconnect on a semi-regular basis, Comet and Polling can be seen as extremes on a spectrum where there are 2 customizable parameters - the connected time and the disconnected time. DWR can manage these dynamically to help manage server load.

Active and Passive Reverse Ajax

DWR can be configured to use Comet/Polling for times when extra load is acceptable, but faster response times are needed. This mode is called active Reverse Ajax. By default DWR starts with active Reverse Ajax turned off, allowing only the piggyback transfer mechanism.

More Information

This site also contains information about getting started with Reverse Ajax, on more advanced configuration, and how to interact with browsers from non-web threads.