Could the WP script/style loader be used to concatenate and gzip scripts and styles in the front-end?

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:

  1. Uncompressed scripts get searched by .dev.js (when SCRIPT_DEBUG is TRUE).
  2. Same seems to be possible for $wp_styles.
  3. EDIT: WP 3.5 will change this behavior and use .js for “dev” versions and “.min.js” when (SCRIPT_DEBUG is TRUE);

(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.

Leave a Comment