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?
February 18th, 2009 at 10:25 pm
This is awesome, I am going to use it!
February 19th, 2009 at 6:56 am
Dude – write a plugin for this by the way… it would be very useful – and I would be happy to reblog it!
March 3rd, 2009 at 5:42 am
Great post… I guess it would be useful to turn into plug-ins…
May 3rd, 2009 at 2:57 pm
That’s a great addition. I think it will make sense to provide this as a plug-in for jQuery. It only makes sense to throttle the number of requests being sent.
June 15th, 2009 at 11:53 am
A very good explanation, helped much!
Thank you!
June 22nd, 2009 at 1:07 pm
Very nice article!
It does work very well and of course that it will be usefull converting it to a plugin.
I´ll be thankfull!
June 25th, 2009 at 4:50 pm
Thanks for sharing this useful tip John!
July 13th, 2009 at 4:40 pm
great tutorial, it helped me a lot ! thanks