Friday, April 3rd, 2009
Poller: YUI3 Small Polling Component
<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:
-
-
var poller = new Y.Poller({
-
url : 'data.json',
-
headers : {"foo":"bar"},
-
interval : 7000,
-
pauseInactive : true
-
});
-
poller.on( 'request', logRequestData );
-
poller.on( 'response', logResponseData );
-
poller.on( 'modified', updateUI );
-
poller.start();
-
Related Content:











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