Skip to main content

Bug Tracker

Side navigation

#7102 closed enhancement (fixed)

Opened September 30, 2010 05:29AM UTC

Closed September 19, 2011 08:38PM UTC

Last modified April 13, 2013 02:25AM UTC

Register jQuery as a CommonjS async module

Reported by: jrburke Owned by: jrburke
Priority: high Milestone: 1.7
Component: core Version: 1.4.4
Keywords: 1.7-discuss Cc:
Blocked by: Blocking:
Description

There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an async module format.

Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading.

There is a test for this change here:

http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html

and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo.

I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request.

Ticket #5742 can be closed out, superseded by this ticket.

Attachments (0)
Change History (32)

Changed September 30, 2010 05:32AM UTC by jrburke comment:1

Pull request with patch:

http://github.com/jquery/jquery/pull/25

Changed September 30, 2010 02:58PM UTC by SlexAxton comment:2

I just want to say that it would be awesome to not have to patch jQuery to give it support for these async loaders. It kills my ability to use it on a cdn. It's almost no code... :D :D :D

Changed October 02, 2010 05:14PM UTC by snover comment:3

component: unfiledcore
milestone: 1.4.31.5
need: ReviewCommit
priority: undecidedhigh

I put this on the list for jQuery 1.next. Since it has a pull request ready already it is possible it might still land for 1.4.3.

Changed October 14, 2010 06:47AM UTC by snover comment:4

status: newopen

Changed October 14, 2010 10:54PM UTC by anonymous comment:5

I'd love to see this in 1.4.3 if possible. Looks like a simple change since there's a patch.

Changed October 14, 2010 11:50PM UTC by jrburke comment:6

There has been new agreement in the AMD proposal to use "define" instead of "require.def", I plan on updating the patch tonight to reflect the change, upside is the patch will be slightly smaller.

Changed October 15, 2010 07:31AM UTC by anonymous comment:7

The pull request has been updated to use define() instead of require.def() now in accordance with the Async Module API.

http://github.com/jquery/jquery/pull/25

The specific update was done in this commit:

http://github.com/jrburke/jquery/commit/9223483c6631c046e09e31a754660c23e9479e01

and confirmed to work with RequireJS 0.14.3, which conforms to the async module API.

Changed October 19, 2010 01:07AM UTC by snover comment:8

milestone: 1.4.41.5

Retarget all enhancements/features to next major version.

Changed November 23, 2010 05:01PM UTC by jitter comment:9

owner: → jrburke
status: openassigned
version: 1.4.21.4.4

Pull request available see comment 7

Changed December 02, 2010 04:56AM UTC by jrburke comment:10

I did a small update to the pull request, registering jQuery as a named module. I used "jquery" instead of "jQuery" since the module IDs in CommonJS are normally mapped to file names at some point, and normally jQuery is distributed via file names that are in lowercase.

I made the change so that jQuery is more robust to mixing in environments where anonymous modules are supported but used alongside library code on the page that may have combined jQuery in with other scripts or modules using optimization strategies that are not aware of anonymous modules. When combining multiple anonymous modules together in a file, the combination process needs to be sure to give each anonymously define()'d module a name.

However, there will be many people using jQuery that use script combination processes that are not aware of anonymous modules, so it is best to name jQuery's define()'d module. This will allow it to work well in pages that mix anonymous-unaware code with other anonymous-aware code.

This is the same approach I recommend for any jQuery plugins that want to optionally opt-in to define()ing a module, and something I advocated recently at the online jQuery summit conference.

Changed December 27, 2010 07:04PM UTC by jrburke comment:11

resolution: → fixed
status: assignedclosed

Register as a CommonJS async module if in that kind of environment. Fixes #7102.

Changeset: 6ffa730721a8ebcd128f3dc202706e46d9cfe249

Changed December 28, 2010 01:31AM UTC by jrburke comment:12

Register as a CommonJS async module if in that kind of environment. Fixes #7102.

Changeset: 6ffa730721a8ebcd128f3dc202706e46d9cfe249

Changed January 05, 2011 09:27PM UTC by wycats comment:13

Revert "Register as a CommonJS async module if in that kind of environment. Fixes #7102."

This reverts commit 6ffa730721a8ebcd128f3dc202706e46d9cfe249.

Conflicts:

src/core.js

Changeset: ae6655bcb6d852b79df2ddc5545832c5d08936f4

Changed January 06, 2011 06:55PM UTC by jrburke comment:14

I will send another pull request that includes updated checking for define.amd and define.amd.multiversion, and it will include the test that csnover added as part of the original commit.

The AMD API page has been updated to contain information about the define.amd property.

RequireJS has added this property, and there is a test page that confirms the jQuery change works with an AMD loader.

Please let me know if you need more information or changes. I will post back to this ticket with the pull request URL after publishing this comment.

Changed January 06, 2011 06:56PM UTC by jrburke comment:15

Changed January 14, 2011 08:00PM UTC by jitter comment:16

milestone: 1.51.6
resolution: fixed
status: closedreopened

Changed January 14, 2011 08:00PM UTC by jitter comment:17

status: reopenedopen

Changed April 16, 2011 09:34PM UTC by john comment:18

milestone: 1.61.next

Let's discuss this for 1.7.

Changed April 17, 2011 04:52AM UTC by jrburke comment:19

I updated the pull request to this one (supersedes the old one):

https://github.com/jquery/jquery/pull/331

It has *just* the changes needed for this ticket, and specifies a special define.amd.jQuery capability flag that is used to indicate if the AMD loader can deal with multiple versions of jQuery calling define. See the pull request for more info, and matching tests/changes in RequireJS to work with capability flag.

Changed May 22, 2011 07:27PM UTC by john comment:20

keywords: → 1.7-discuss

Nominating ticket for 1.7 discussion.

Changed May 22, 2011 10:04PM UTC by rwaldron comment:21

description: There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format]. \ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading. \ \ There is a test for this change here: \ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html \ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo. \ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request. \ \ Ticket #5742 can be closed out, superseded by this ticket.There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format].\ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading.\ \ There is a test for this change here:\ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html\ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo.\ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request.\ \ Ticket #5742 can be closed out, superseded by this ticket.

+1, Alot of work has gone into this, https://github.com/jquery/jquery/pull/331

Changed May 23, 2011 12:12AM UTC by jaubourg comment:22

+0, I know why people want this but I'd rather wait for a standard module system in JS. Is it that difficult to embed jQuery as a module? Do we absolutely need this in core?

Changed May 23, 2011 02:00AM UTC by ajpiano comment:23

description: There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format].\ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading.\ \ There is a test for this change here:\ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html\ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo.\ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request.\ \ Ticket #5742 can be closed out, superseded by this ticket.There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format]. \ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading. \ \ There is a test for this change here: \ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html \ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo. \ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request. \ \ Ticket #5742 can be closed out, superseded by this ticket.

+1, Yes, we have to stop making this difficult for people.

Changed May 23, 2011 03:45AM UTC by timmywil comment:24

description: There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format]. \ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading. \ \ There is a test for this change here: \ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html \ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo. \ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request. \ \ Ticket #5742 can be closed out, superseded by this ticket.There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format].\ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading.\ \ There is a test for this change here:\ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html\ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo.\ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request.\ \ Ticket #5742 can be closed out, superseded by this ticket.

+1, I would love this.

Changed May 23, 2011 09:55PM UTC by dmethvin comment:25

description: There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format].\ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading.\ \ There is a test for this change here:\ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html\ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo.\ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request.\ \ Ticket #5742 can be closed out, superseded by this ticket.There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format]. \ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading. \ \ There is a test for this change here: \ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html \ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo. \ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request. \ \ Ticket #5742 can be closed out, superseded by this ticket.

+1

Changed June 03, 2011 01:39PM UTC by john comment:26

description: There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format]. \ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading. \ \ There is a test for this change here: \ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html \ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo. \ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request. \ \ Ticket #5742 can be closed out, superseded by this ticket.There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format].\ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading.\ \ There is a test for this change here:\ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html\ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo.\ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request.\ \ Ticket #5742 can be closed out, superseded by this ticket.

+1, Seems trivial enough!

Changed June 04, 2011 10:16PM UTC by addyosmani comment:27

+1

Changed June 06, 2011 03:55PM UTC by jzaefferer comment:28

+1, surprisingly little change necessary

Changed July 11, 2011 05:35PM UTC by ajpiano comment:29

description: There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format].\ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading.\ \ There is a test for this change here:\ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html\ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo.\ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request.\ \ Ticket #5742 can be closed out, superseded by this ticket.There are a couple browser-based CommonJS-friendly loaders (RequireJS, Yabble) that can load modules that use an [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition async module format]. \ \ Ideally jQuery would register itself as a module using this format. This would allow jQuery to participate in browser module loading with these compatible loaders. Right now a patched version of jQuery is needed to accomplish this behavior. This approach also makes it easier for script loaders to use the new jQuery.readyWait feature to indicate other async scripts are loading and to not fire the jQuery ready callbacks until the scripts finish loading. \ \ There is a test for this change here: \ http://github.com/jrburke/requirejs/blob/master/build/jquery/test.html \ \ and I verified the change works by the jquery-master.js patched jQuery file that is a sibling to test.html. I am happy to reconfirm the change if it is committed to the master repo. \ \ I will attach a pull request link to this ticket that has the code change after I create the ticket so I can put the ticket number in the pull request. \ \ Ticket #5742 can be closed out, superseded by this ticket.
milestone: 1.next1.7

Changed September 08, 2011 07:15AM UTC by thomasalwyndavis@gmail.com comment:30

Definitely a step forward for clearing up the global namespace.

Changed September 19, 2011 08:38PM UTC by jrburke comment:31

resolution: → fixed
status: openclosed

Landing pull request 331. Add support for registering jQuery as an AMD module. Fixes #7102.

More Details:

Changeset: bba3d610c7e3b611fe1eb89178c91106a156a5dc

Changed April 13, 2013 02:25AM UTC by anonymous comment:32

Replying to [comment:1 jrburke]:

Pull request with patch: http://github.com/jquery/jquery/pull/25