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

Fix #12838: hook point for non-jQuery.ajax synchronous script fetch/execute in domManip #1051

Closed
wants to merge 3 commits into from

Conversation

gibson042
Copy link
Member

I'm not thrilled about the name, but at least it's unambiguous.

Sizes - compared to master @ c2d6847

    264083       (+44)  dist/jquery.js                                         
     92059       (+60)  dist/jquery.min.js                                     
     32626       (+11)  dist/jquery.min.js.gz

@@ -1666,8 +1666,10 @@ module( "ajax", {
//----------- jQuery.getScript()

asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() {
Globals.register("foobar");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really love this Globals system :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I always test with the globals check on and this wasn't caught...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? I just tried on Chromium and found several globals leaking in ajax tests; mostly from jsonp. I assumed it was already on your radar, but now I'm wondering if it's environment-specific.

@gibson042
Copy link
Member Author

Updated for the new year! Also, @jaubourg was right... putting this alongside ajax methods with which it has little in common is just begging for bug reports. So manipulation it is!

   raw     gz Sizes                                                             
239589  71007 dist/jquery.js                                                    
 82978  29518 dist/jquery.min.js                                                

   raw     gz Compared to master @ 32b066d3805a48f8c8312562ed52a1b5910b1d85     
   +35     -3 dist/jquery.js                                                    
   +52    +17 dist/jquery.min.js

global: false,
"throws": true
});
jQuery._evalUrl( node.src );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1, No new API surface.

I'm sorry, but we need to find another way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not so much surface API as it is a simple hook. It's clearly marked as private (leading underscore).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is literally impossible to satisfy #12838 without new API surface. We may opt not to do it, but we will not find "another way".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other way I see is to have a global core_evalUrl variable and require anyone who wants to override the ajax module to do a custom build.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other way I see is to have a global core_evalUrl variable and require anyone who wants to override the ajax module to do a custom build.

It's not practical. One would be expected to have a build without ajax and be able to use this build with whatever third party ajax lib (or none: $._evalURL = $.noop;) they see fit, not have to rebuild a custom version per third-party. Having to override a variable in the closure at build time is overkill when a private overridable hook on the jQuery object does the job perfectly.

I understand rick's reservations with this but I don't think we can offer a practical solution any other way. We can build jQuery without ajax now, so we should provide this hook.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a script element being created and appended to the document.head: https://github.com/jquery/jquery/blob/master/src/ajax/script.js#L34-L48 which would be invoked as a result of this call site: https://github.com/jquery/jquery/blob/master/src/manipulation.js#L335-L345

Is that incorrect?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a script element being created and appended to the document.head: https://github.com/jquery/jquery/blob/master/src/ajax/script.js#L34-L48 which would be invoked as a result of this call site: https://github.com/jquery/jquery/blob/master/src/manipulation.js#L335-L345
Is that incorrect?

Yes, it is incorrect. Transport selection is a bit more involved than a simple one-on-one correspondance with a dataType. You missed the condition here: https://github.com/jquery/jquery/blob/master/src/ajax/script.js#L30

If it's not a crossDomain request, then ajax will continue searching for a suitable transport, until it reaches the one in xhr.js. Effectively enabling synchronous same-domain requests. Executing scripts synchronously is mandatory for domManip. It is, and always has been, broken for scripts of another domain but that's beside the point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the custom ajax lib doesn't do any of this? Can it just use a script element?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't load a script using script tag injection synchronously.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know—thank you—but that's not what I asked.

I concede, let's pile more ugly "_" junk onto jQuery. Can't wait for the bug reports.

@gibson042 gibson042 closed this in 03db1ad Apr 17, 2013
gibson042 added a commit that referenced this pull request Apr 17, 2013
…xecute in domManip. Close gh-1051.

(cherry picked from commit 03db1ad)
mescoda pushed a commit to mescoda/jquery that referenced this pull request Nov 4, 2014
@somixyz

This comment has been minimized.

Copy link

@nandagopalt nandagopalt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@lock lock bot locked as resolved and limited conversation to collaborators Jun 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

7 participants