Commit c373a499 authored by jaubourg's avatar jaubourg Committed by Dave Methvin

Reduced script transport

parent 359e3f57
...@@ -14,71 +14,45 @@ jQuery.ajaxSetup({ ...@@ -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 ) { jQuery.ajaxPrefilter( "script", function( s ) {
if ( s.cache === undefined ) { if ( s.cache === undefined ) {
s.cache = false; s.cache = false;
} }
if ( s.crossDomain ) { if ( s.crossDomain ) {
s.type = "GET"; s.type = "GET";
s.global = false;
} }
}); });
// Bind script tag hack transport // Bind script tag hack transport
jQuery.ajaxTransport( "script", function(s) { jQuery.ajaxTransport( "script", function(s) {
// This transport only deals with cross domain requests // This transport only deals with cross domain requests
if ( s.crossDomain ) { if ( s.crossDomain ) {
var callback;
var script,
head = document.head || jQuery("head")[0] || document.documentElement;
return { return {
send: function( _, complete ) {
send: function( _, callback ) { callback = function( type ) {
return function() {
script = document.createElement("script"); callback = script.onload = script.onerror = null;
jQuery( script ).remove();
script.async = true; if ( type ) {
complete( type === "success" ? 200 : 404, type );
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 );
} }
};
// Dereference the script
script = null;
// Callback if not abort
if ( !isAbort ) {
callback( 200, "success" );
}
}
}; };
var script = jQuery.extend( document.createElement("script"), {
// Circumvent IE6 bugs with base elements (#2709 and #4378) by prepending async: true,
// Use native DOM manipulation to avoid our domManip AJAX trickery charset: s.scriptCharset,
head.insertBefore( script, head.firstChild ); src: s.url,
onload: callback("success"),
onerror: callback("error")
});
callback = callback();
document.head.appendChild( script );
}, },
abort: function() { abort: function() {
if ( script ) { if ( callback ) {
script.onload( undefined, true ); callback();
} }
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment