diff options
author | jaubourg <j@ubourg.net> | 2013-01-09 02:01:13 +0100 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2013-01-20 18:08:59 -0500 |
commit | c373a499d39e35172f9b93af993681e4b5f0908b (patch) | |
tree | e6be773ca4baf1e885b8e3637b03a2d464dff1b3 | |
parent | 359e3f57466e508ccfc3e30acfc2aee0c52df83c (diff) | |
download | jquery-c373a499d39e35172f9b93af993681e4b5f0908b.tar.gz jquery-c373a499d39e35172f9b93af993681e4b5f0908b.zip |
Reduced script transport
-rw-r--r-- | src/ajax/script.js | 68 |
1 files changed, 21 insertions, 47 deletions
diff --git a/src/ajax/script.js b/src/ajax/script.js index ac14c44be..b5d377571 100644 --- a/src/ajax/script.js +++ b/src/ajax/script.js @@ -14,71 +14,45 @@ jQuery.ajaxSetup({ } }); -// Handle cache's special case and global +// Handle cache's special case and crossDomain jQuery.ajaxPrefilter( "script", function( s ) { if ( s.cache === undefined ) { s.cache = false; } if ( s.crossDomain ) { s.type = "GET"; - s.global = false; } }); // Bind script tag hack transport jQuery.ajaxTransport( "script", function(s) { - // This transport only deals with cross domain requests if ( s.crossDomain ) { - - var script, - head = document.head || jQuery("head")[0] || document.documentElement; - + var callback; return { - - send: function( _, callback ) { - - script = document.createElement("script"); - - script.async = true; - - if ( s.scriptCharset ) { - script.charset = s.scriptCharset; - } - - script.src = s.url; - - // Attach handlers for all browsers - script.onload = script.onreadystatechange = function( _, isAbort ) { - - if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) { - - // Handle memory leak in IE - script.onload = script.onreadystatechange = null; - - // Remove the script - if ( script.parentNode ) { - script.parentNode.removeChild( script ); + send: function( _, complete ) { + callback = function( type ) { + return function() { + callback = script.onload = script.onerror = null; + jQuery( script ).remove(); + if ( type ) { + complete( type === "success" ? 200 : 404, type ); } - - // Dereference the script - script = null; - - // Callback if not abort - if ( !isAbort ) { - callback( 200, "success" ); - } - } + }; }; - - // Circumvent IE6 bugs with base elements (#2709 and #4378) by prepending - // Use native DOM manipulation to avoid our domManip AJAX trickery - head.insertBefore( script, head.firstChild ); + var script = jQuery.extend( document.createElement("script"), { + async: true, + charset: s.scriptCharset, + src: s.url, + onload: callback("success"), + onerror: callback("error") + }); + callback = callback(); + document.head.appendChild( script ); }, - abort: function() { - if ( script ) { - script.onload( undefined, true ); + if ( callback ) { + callback(); } } }; |