[wp-trac] [WordPress Trac] #16343: API for WP_Scripts: allow async loading, version checks

WordPress Trac wp-trac at lists.automattic.com
Sat Jan 22 18:07:39 UTC 2011


#16343: API for WP_Scripts: allow async loading, version checks
-------------------------+-------------------------------------------------
 Reporter:  jltallon     |      Owner:  jltallon
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Performance  |    Version:
 Severity:  minor        |   Keywords:  WP_Scripts, async-load, cache-
                         |  friendliness
-------------------------+-------------------------------------------------
 When developping a theme lately, I have found myself in the need of
 directly accesing the internals of the WP_Scripts class. I feel the
 funcionality I need might well help other developers.


 Use cases:

 1.- Asynchronously load a (JS) script loaded by a/another plugin

   When loading a certain page, we needed to asynchronously load some
 (relatively heavy) scripts which are only seldom used. In order to keep
 page rendering fast, we only load them on demand, after the page frame has
 been rendered.
   In order to avoid having to bundle (potentially conflicting versions)
 scripts in every plugin and prevent duplicate loading, I suggest adding an
 API which would enable querying the source (as used by 'scripts-loader')


 2.- Version checks for loaded scripts

   For high-performance sites, it might be useful to load a Google (or some
 other CDN) -provided jQuery et al ---which the user might already have
 cached--- instead of the bundled one, as long as it is the same version.

  Code example:
    $ver = $wp_scripts->version('jquery');
    wp_unregister_script('jquery');
 wp_register_script('jquery',"http://ajax.googleapis.com/jquery/$ver/jquery.min.js",false,$ver);


 (needs discussion)



 I can provide the code (or the patch against Core) when the solution is
 decided (or soonish, if a proof-of-concept is needed)
 If WP 3.2 is going to finally be PHP 5.2+, I'd rather basically rewrite
 WP_Scripts (and/or WP_Dependencies).

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16343>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list