Converting Prototype’s Ajax.PeriodicalUpdater to jQuery

Bookmark and Share

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.

Tags: ,

This entry was posted on Wednesday, February 18th, 2009 at 9:54 pm and is filed under AJAX, jquery, web development. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

 

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

  1. Steve ReynoldsNo Gravatar Says:

    This is awesome, I am going to use it!

  2. Steve ReynoldsNo Gravatar Says:

    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. arquivos deslizantes spNo Gravatar Says:

    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. Tyres BedfordNo Gravatar Says:

    Thanks for sharing this useful tip John!

  8. anunturiNo Gravatar Says:

    great tutorial, it helped me a lot ! thanks