The Dojo project has pioneered the implementation of the Bayeux specification, but for example the jQuery project lacked a robust client-side Cometd implementation.

This gap has been filled now, with a shared pure-JavaScript implementation and bindings for both Dojo and jQuery.
This means that the bulk of the Cometd implementation is now in a single, pure-JavaScript file, and that users of either toolkit have a binding (a very small adapter code) that allows developers to use the JavaScript Cometd API as a first class citizen in the either toolkit.

As a small example, this is how you use it in Dojo:

dojox.cometd.publish('/mychannel', { mydata: 'foobar' });

and this is how you use it in jQuery:

$.cometd.publish('/mychannel', { mydata: 'foobar' });


A good side effect of all this is that every bug or new feature is fixed or added to the shared pure-JavaScript file, and immediately both toolkits will benefit of that.

The implementation has been totally rewritten since the one historically present in Dojo, and the following are the most interesting features:

  • better support for tweaking the configuration
  • split configuration and initialization steps to allow more flexibility in case of programmatic disconnects
  • extended and clarified the Cometd APIs
  • better notifications for failures due to server or network failures
  • automatic and configurable connection retries
  • incoming message and outgoing message interception
  • automatic bayeux transport negotiation, supporting long-polling and callback-polling transports
  • extensions such as timesync, message acknowledgement and transparent page reload

Downloads, documentation and code is available at the Cometd website.

JavaScript Cometd Implementation Refactored

2 thoughts on “JavaScript Cometd Implementation Refactored

  • October 2, 2010 at 4:23 pm

    I can tell you are the main contributor for cometd and I must tell you…Its a wonderful framework. I’ve been using it extensively.
    Im currently working on a new project in my spare time and was attempting to get the latest and greatest (cometd 2.0.0) to work with Spring. I’ve not had much luck. I saw your post on 2.0 bugs and see that there is a spring config for 2.0.1 which uses the BayeuxServerImpl. Apparently, I need to run it with the 2.0.1-SNAPSHOT. Problem is i can’t seem to find them in any maven repository.
    Your help is much appreciated.

  • October 2, 2010 at 5:30 pm

    @Bob: I updated the main page of with a link to the Maven2 Snapshot Repository.
    Thanks for the heads up.

Comments are closed.