Skip to content
Permalink
Browse files

Added a simple cache for xhr objects in the xhr transport.

  • Loading branch information...
jaubourg committed Jan 9, 2011
1 parent 368f244 commit 98c6c4b2b0afb2754883fc39c5626da3219e81e0
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/ajax/xhr.js
@@ -6,6 +6,9 @@ var // Next fake timer id
// Callbacks hashtable
xhrs = {},

// XHR pool
xhrPool = [],

// #5280: see end of file
xhrUnloadAbortMarker = [];

@@ -21,7 +24,7 @@ jQuery.ajax.transport( function( s , determineDataType ) {

send: function(headers, complete) {

var xhr = s.xhr(),
var xhr = xhrPool.pop() || s.xhr(),
handle;

// Open the socket
@@ -53,6 +56,8 @@ jQuery.ajax.transport( function( s , determineDataType ) {
try {
xhr.send( ( s.hasContent && s.data ) || null );
} catch(e) {
// Store back in pool
xhrPool.push( xhr );
complete(0, "error", "" + e);
return;
}
@@ -64,10 +69,12 @@ jQuery.ajax.transport( function( s , determineDataType ) {
if ( callback && ( abortStatusText || xhr.readyState === 4 ) ) {

// Do not listen anymore
// and Store back in pool
if (handle) {
xhr.onreadystatechange = jQuery.noop;
delete xhrs[ handle ];
handle = undefined;
xhrPool.push( xhr );
}

callback = 0;

0 comments on commit 98c6c4b

Please sign in to comment.
You can’t perform that action at this time.