John McCollum

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?

View the demonstration here.

Posted in AJAX, jquery, web development by admin at February 18th, 2009.
Tags: ,

8 Responses to “Converting Prototype’s Ajax.PeriodicalUpdater to jQuery”

  1. This is awesome, I am going to use it!

  2. Dude – write a plugin for this by the way… it would be very useful – and I would be happy to reblog it!

  3. bakuganNo Gravatar says:

    Great post… I guess it would be useful to turn into plug-ins…

  4. JeetNo Gravatar says:

    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.

  5. MudançasNo Gravatar says:

    A very good explanation, helped much!
    Thank you!

  6. 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!

  7. Thanks for sharing this useful tip John!

  8. anunturiNo Gravatar says:

    great tutorial, it helped me a lot ! thanks

Leave a Reply

This site is using OpenAvatar based on