Converting Prototype’s Ajax.PeriodicalUpdater to jQuery
One of the things I missed when switching from Prototype to jQuery was the former’s Ajax.PeriodicalUpdater function. It is used to provide a ‘decay’ mechanism for ajax calls, making them less and less frequent if the retrieved content doesn’t change inbetween calls.
It can be a seriously useful piece of functionality. I took a chatroom that was polling every second and using an entire CPU core (50% usage!) and reduced it to 2-3% using this method. There were also errors retrieving content because sometimes the responses would take longer than a second to come back!
The problem is, there really isn’t a similar piece of functionality in jQuery.
So here it is! The script checks the returned data against previously received data, and increases the time between calls if it hasn’t changed.
I’d be interested in your comments. Would it be useful to turn this into a plugin?
