Friday, April 3rd, 2009

Poller: YUI3 Small Polling Component

Category: JavaScript, Yahoo!

<p>Eric Ferraiuolo has created a YUI3 component for smart polling which means:

  • Use conditional GET requests
  • Retain the most recent Etag and Last-Modified date of the polled resource
  • Disable polling when the browser window is inactive

Implementing a smart polling process in our application’s rich UI gives us some desired benefits:

  • Removal of the refresh button
  • Automatic updating of the UI when the resource on the server has changed
  • Less repainting of the page since the DOM is touched only when the data has changed
  • Changes to the UI only happen when the window is active (the user sees them) as polling is paused while the user is doing something else

The component that Eric wrote means that you can set of a poller like this:

javascript
< view plain text >
  1. var poller = new Y.Poller({
  2.     url : 'data.json',
  3.     headers : {"foo":"bar"},
  4.     interval : 7000,
  5.     pauseInactive : true
  6. });
  7. poller.on( 'request', logRequestData );
  8. poller.on( 'response', logResponseData );
  9. poller.on( 'modified', updateUI );
  10. poller.start();

Related Content:

Posted by Dion Almaer at 6:05 am
1 Comment

+++--
3.6 rating from 34 votes

1 Comment »

Comments feed TrackBack URI

hooray for conditional get… too bad most people dont even know what that is yet, but its very forward thinking.

Comment by ilazarte — April 3, 2009

Leave a comment

You must be logged in to post a comment.