Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script tags now used for most async requests in 4.0 #1271

Open
mgol opened this issue Apr 2, 2025 · 0 comments
Open

Script tags now used for most async requests in 4.0 #1271

mgol opened this issue Apr 2, 2025 · 0 comments
Milestone

Comments

@mgol
Copy link
Member

mgol commented Apr 2, 2025

The full logic for whether to use the script tag is implemented by this function:

function canUseScriptTag( s ) {

	// A script tag can only be used for async, cross domain or forced-by-attrs requests.
	// Requests with headers cannot use a script tag. However, when both `scriptAttrs` &
	// `headers` options are specified, both are impossible to satisfy together; we
	// prefer `scriptAttrs` then.
	// Sync requests remain handled differently to preserve strict script ordering.
	return s.scriptAttrs || (
		!s.headers &&
		(
			s.crossDomain ||

			// When dealing with JSONP (`s.dataTypes` include "json" then)
			// don't use a script tag so that error responses still may have
			// `responseJSON` set. Continue using a script tag for JSONP requests that:
			//   * are cross-domain as AJAX requests won't work without a CORS setup
			//   * have `scriptAttrs` set as that's a script-only functionality
			// Note that this means JSONP requests violate strict CSP script-src settings.
			// A proper solution is to migrate from using JSONP to a CORS setup.
			( s.async && jQuery.inArray( "json", s.dataTypes ) < 0 )
		)
	);
}

We should document it.

@mgol mgol added this to the 4.0.0 milestone Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant