WP has a nice javascript loader included in wp-admin:
http://core.trac.wordpress.org/browser/tags/3.0.4/wp-admin/load-scripts.php
and a CSS loader:
http://core.trac.wordpress.org/browser/tags/3.0.4/wp-admin/load-styles.php
I was wondering if it’s possible to use them in the front-end too, not just admin, because they can concatenate all enqueued scripts, and serve them as a single gzipped file
late answer
From a brief look:
You’d have to use
include( admin_url().'load-scripts.php' );
- and
include( admin_url().'script-loader.php' );
Then jump into $GLOBALS['wp_scripts']
:
Use…
$wp_scripts->default_dirs( array_merge(
$wp_scripts->default_dirs
,array( '/themes/your_theme/js/' )
);
…to extend it.
And then use
$wp_scripts->add( $handle, $path_from_content_dir, false/array( $deps ), $ver )
to add a script.
Notes:
- Uncompressed scripts get searched by
.dev.js
(whenSCRIPT_DEBUG
isTRUE
). - Same seems to be possible for
$wp_styles
. - EDIT: WP 3.5 will change this behavior and use
.js
for “dev” versions and “.min.js” when (SCRIPT_DEBUG
isTRUE
);
(But I guess this will only work if you use a plugin or mu-plugin.)
It´s not tested and I´m not shure if this will work.