[wp-trac] [WordPress Trac] #23285: Implement an AMD JavaScript loader in WordPress
WordPress Trac
noreply at wordpress.org
Thu Jan 24 14:28:48 UTC 2013
#23285: Implement an AMD JavaScript loader in WordPress
-----------------------------+-----------------------------
Reporter: auniquename | Type: feature request
Status: new | Priority: normal
Milestone: Awaiting Review | Component: General
Version: | Severity: normal
Keywords: |
-----------------------------+-----------------------------
AMD = Asynchronous Module Definition
See comment: http://core.trac.wordpress.org/ticket/22896#comment:29
I think this is a must for the future viability of WordPress and plugins
written for it.
Multiple versions of JavaScript libraries are a fact of life and we have
to deal with it somehow.
If WordPress provides the framework for the use of multiple versions of
JavaScript libraries then a lot of the problems we see with WordPress now
will be a thing of the past.
This represents a major re-think of the current WordPress JavaScript
loading paradigm, but I think it is necessary and would be well worth it.
I'm not a terribly advanced developer, and there might be better solutions
out there or others to come, but for now, I think this is the way to go.
Example:
http://requirejs.org/docs/why.html
http://requirejs.org/docs/whyamd.html
https://github.com/amdjs/amdjs-api/wiki/AMD
It does not have to be RequireJS, but it seems the most mature and popular
of the implementations.
From the unminified jQuery source:
{{{
// Expose jQuery as an AMD module, but only for AMD loaders that
// understand the issues with loading multiple versions of jQuery
// in a page that all might call define(). The loader will indicate
// they have special allowances for multiple jQuery versions by
// specifying define.amd.jQuery = true. Register as a named module,
// since jQuery can be concatenated with other files that may use define,
// but not use a proper concatenation script that understands anonymous
// AMD modules. A named AMD is safest and most robust way to register.
// Lowercase jquery is used because AMD module names are derived from
// file names, and jQuery is normally delivered in a lowercase file name.
// Do this after creating the global so that if an AMD module wants to
call
// noConflict to hide this version of jQuery, it will work.
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
define( "jquery", [], function () { return jQuery; } );
}
}}}
Note: '''multiple versions of jQuery'''
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23285>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list