• Skip to main content
  • Skip to footer

ClipBank

Customize WordPress Themes and Plugins

  • Users
    • How to Add a Precoded Clip
  • Devs
    • New Author Registration
    • Submit a Precoded Clip
    • Precoding a Clip
  • WP Clips
  • Login

WP Clips Combine and Minify

v1.0.2
Dwnlds700

This Clip combines and minifies the custom CSS stylesheets and JS scripts of all active Clips in the WP Clips plugin, and optionally minifies resulting HTML output.

Category: Free Clips
  • Download
  • Setup
  • Author
  • Discuss
Requirements
WP Clips - download and install latest version


Installation / Updates
  1. Download the Precoded Clip zip file.
  2. clip-wp-clips-combine-minify.1.0.2.zip

    Download Clip
  3. Ensure WP Clips plugin is installed. Go to Settings > Clips in WordPress admin and install via 'WP Clips Control'; OR unzip and upload via FTP (or file manager) to the /wp-clips/precoded/ directory.

Credits / Sponsors
Clip authored by : Jon Barratt

Bennett Stone (magic-min) https://github.com/bennettstone
Fulvio Notarstefano (html-compression) https://gist.github.com/unfulvio

Description

USING THE CLIP

Enqueued files are automatically minified and combined on a page’s first load. This may take a few seconds. The resulting minified/combined files are only refreshed when –

  1. a new CSS or JS file is added
  2. an existing CSS or JS file is modified
  3. Clips are updated via ‘WP Clips Control’

A refresh can be ‘forced’ by clicking the Update button in ‘WP Clips Control’.

Setting Conditional Enqueues

By default, the Clip creates two sets of combined/minified files. One set is for the front-page, and the other is for all remaining pages. If any stylesheets/scripts (other than front-page) are enqueued conditionally (e.g. if( is_archive() ) ), the condition should be added via a filter to trigger a new set of combined/minified files.

For example, if additional CSS/JS files are enqueued only on a single post, and another set only on a WooCommerce product archive, you would add the following code to the custom Clip to create two new combined/minified file sets under those conditions –

// Add conditions for new minified file sets
add_filter( 'clip_minify_styles_conds', 'example_function' ); // for CSS
add_filter( 'clip_minify_scripts_conds', 'example_function' ); // for JS
function example_function( $conds ) {
    $new_conds = array( is_single(), is_woocommerce() && is_archive() ); // conditions
    foreach( $new_conds as $new_cond ) {
        if( ! in_array( $new_cond, $conds )
            $conds[] = $new_cond;
    }
    return $conds;
}

Note: Always refresh caches after changes.

OPTIONS

If you wish to enable HTML minifying, add the following code to your custom Clip’s custom-functions.php file –

// Enable minify for HTML output
add_action( 'get_header', 'clip_minify_html' );

If you wish to disable combine and minify for CSS stylesheets and JS scripts, add the appropriate code below to your custom Clip’s custom-functions.php file –

// Disable combine and minify for CSS stylesheets
remove_action( 'wp_enqueue_scripts', 'clip_combine_minify_styles', 99 );
// Disable combine and minify for JS scripts
remove_action( 'wp_enqueue_scripts', 'clip_combine_minify_scripts', 99 );

Note: Always refresh caches after changes.

NOTES

When activated and on load, this Clip adds combined/minified files to the Clip’s /files/ directory.

The Clip uses a modified version of Bennett Stone’s magic-min script at https://github.com/bennettstone/magic-min.

MORE INFORMATION

https://github.com/bennettstone/magic-min (magic-min)
https://gist.github.com/unfulvio/5889564 (html-compression)

Jon Barratt
Jon has worked in a variety of creative disciplines over 25 years, including 17 years at the helm of Zynke Design, one of Australia’s most established design studios. He’s been credited on several films, is a qualified strategic intervention coach, and now lives and breathes WordPress, Genesis and WP Clips!


Clips: https://clipbank.wpclips.net/vendors/krolyn/
Website: http://www.krolyn.com

Got something to discuss?


 
Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin
Share on StumbleUpon
StumbleUpon
  • WP Clips
  • WP Clips Multisite
  • ClipBank

© Copyright 2015 Krolyn Studios · Privacy Policy · Contact Us