jqueryonreadystatechange

onreadystatechange in jQuery v1.4


The new jQuery v1.4 says this...

jQuery.ajax() is now using onreadystatechange instead of a timer

Ajax requests should now take fewer resources by using onreadystatechange instead of polling.

I am not sure exactly what this means but on my site (social network like facebook, myspace) I have notifications that user's get, it makes AJAX call periodicly to see if there is new notifications to show on a page, is this something that can improve the way stuff like that is done?


Solution

  • Yes it would improve your site. Depending on how much AJAX your site uses, the improvement will not be noticeable in speed as much as lower system resources being used during the call.

    IE6 does not support onreadystatechange so I assume it will fall back to the timer for IE6, but most other browser implementations of XMLHTTPRequest support that event. Event callbacks always use less resources than a polling script (that checks something every few milliseconds).

    Regarding IE6

    The onreadystatechange event was introduced in Windows Internet Explorer 7. Source: MSDN