Skip to content

Commit

Permalink
Reduced script transport
Browse files Browse the repository at this point in the history
  • Loading branch information
jaubourg authored and dmethvin committed Jan 20, 2013
1 parent 359e3f5 commit c373a49
Showing 1 changed file with 21 additions and 47 deletions.
68 changes: 21 additions & 47 deletions src/ajax/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

This comment has been minimized.

Copy link
@ykopstein

ykopstein Jan 7, 2019

@jaubourg @dmethvin This was first added in ab3ba4a from what I can see. It was removed here. There's no information in either place why the change was made. Can you elaborate?

(I'm working w/ an old version of jQuery that still sets global=false on cross domain script requests)

This comment has been minimized.

Copy link
@dmethvin

dmethvin Jan 9, 2019

Member

@ykosbie this isn't a good place to discuss a problem. Please file a ticket describing the issue and a test case that demonstrates the problem.

}
});

// 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();
}
}
};
Expand Down

0 comments on commit c373a49

Please sign in to comment.