Tag Archive for 'Ajax'

Smart Polling

I’m working on the rich UI of a small web application which has a problem I need to solve: the data from the server which the UI is presenting could change at any time. The first iteration of the UI has a refresh button. Clicking this button sends an Ajax request to a resource on the server which responds with a JSON data structure, and the UI is updated with any changes in the new data. My business partner doesn’t like the refresh button; he questions why it’s there and states how annoying it is to press the button all the time. His suggestion is the rich UI should smartly poll the server for changes to the data, and update the UI automatically.

Intrigued by his idea, we continued our discussion leading to a definition for what it means to smartly poll a server’s resource:

  • 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

Creating a reusable component to achieve a smart polling process feels like the correct approach as I foresee a need to use this functionality in future projects as well. Continue reading ‘Smart Polling’

Using Google’s Ajax APIs

To put it simply, Google’s Ajax APIs are cool and useful! I love checking out the Google Code site and seeing new APIs listed, just shows they’re really put a lot of effort into this area of their business.

Google has their different APIs categorized, one of these categories is Ajax, I wanted to write about these APIs in particular as they have real-world uses that can get off the ground quickly.

Continue reading ‘Using Google’s Ajax APIs’