Add support for registering jQuery as an AMD module. Only does so if the #331

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants
Contributor

jrburke commented Apr 17, 2011

Add support for registering jQuery as an AMD module. Only does so if the AMD loader indicates it has special allowances for multiple versions of jQuery being loaded in a page.

The "special allowances" should be:

  • Being able to restrict registration of jQuery to a specific version.
  • Allow multiple versions of jQuery to be loaded in a page if the loader supports different "sandboxes" for defined modules.

An AMD loader needs to have these special allowances for jQuery since jQuery is commonly used by third-party libs used in pages that can load more than one version of jQuery in a page. While this conceptually could happen with any library/toolkit script, jQuery's popularity make it an actual issue, and an AMD loader needs to be able to account for it, or specifically tells its users the restrictions it has with its use and jQuery.

With this RequireJS commit, RequireJS demonstrates meeting these allowances by allowing the developer to specify the version of jQuery they want to allow registered, so if more than one jQuery with a define() call happens, RequireJS will only pay attention to the desired version. The RequireJS commit contains some unit tests to show either 1.4.4 for 1.5.2 being used depending on version set in the RequireJS config.

This helps avoid the issue of some other third party code on a page accidentally loading a version of jQuery the main page developer was not expecting and have it clobber the one that was desired.

RequireJS also supports "contexts" that act like "sandboxes" and allow the developer to load two different versions of jQuery to be loaded and used in a page, as long as jQuery uses define() to register.

RequireJS 1.0 can support this model if/when jQuery decides to accept this pull request, as long as we agree that define.amd.jQuery === true is the capability name/test. If the jQuery project prefers a different capability name, just let me know (preferably within the next week), and I can have the capability flag in the RequireJS 1.0 release.

This pull request includes a define qunit test that was originally authored by csnover, but changed to fit the current suggested capability check.

@jrburke jrburke Add support for registering jQuery as an AMD module. Only does so if …
…the AMD loader indicates it has special allowances for multiple versions of jQuery being loaded in a page.
0b1c2e6
Member

jeresig commented Apr 17, 2011

For reference, this patch is related to: http://bugs.jquery.com/ticket/7102

Owner

dmethvin commented Apr 20, 2011

With 1.6 now in beta, should this go into our 1.7 wishlist? It would be good to get it into the 1.7 alpha early since jrburke has the pull ready and that would give everyone in the script loader community a heads-up.

Owner

timmywil commented Sep 19, 2011

Landed in commit bba3d61.

timmywil closed this Sep 19, 2011

@mescoda mescoda pushed a commit to mescoda/jquery that referenced this pull request Nov 4, 2014

@jrburke jrburke + timmywil Landing pull request 331. Add support for registering jQuery as an AM…
…D module. Fixes #7102.

More Details:
 - jquery#331
 - http://bugs.jquery.com/ticket/7102
400f3cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment