My favorites | Sign in
Logo
                
Search
for
Updated Oct 14, 2009 by st...@mrclay.org
Labels: Phase-Deploy, Featured
CookBook  
Solutions for more complex Minify configurations

Unless mentioned, all the following snippets go in min/config.php.

Faster Cache Performance

By default, Minify uses Minify_Cache_File. It uses readfile/fpassthru to improve performance over most file-based systems, but it's still file IO. I haven't done comparative benchmarks on all three, but APC/Memcache should be faster.

APC

require 'lib/Minify/Cache/APC.php';
$min_cachePath = new Minify_Cache_APC();

Memcache

You must create and connect your Memcache object then pass it to Minify_Cache_Memcache's constructor.

require 'lib/Minify/Cache/Memcache.php';
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$min_cachePath = new Minify_Cache_Memcache($memcache);

(Slightly) Better Javascript Compression

Minify 2.1.3 comes with Tino Zijdel's JSMin+ 1.1. This is a full parser based on a port of Narcissus. To try it out:

$min_serveOptions['minifiers']['application/x-javascript'] = array('JSMinPlus', 'minify');

This should yield smaller javascript files, but I've tested this only briefly. For production you may want to get the latest version (you must rename it: min/lib/JSMinPlus.php).

Note: JSMin+ has no comment preservation as of 1.3, in case you rely on this.

Best Javascript Compression

If your host can execute Java, you can use Minify's YUI Compressor wrapper. You'll need the latest yuicompressor-x.x.x.jar and a temp directory. Place the .jar in min/lib, then:

function yuiJs($js) {
    require_once 'Minify/YUICompressor.php'; 
    Minify_YUICompressor::$jarFile = dirname(__FILE__) . '/lib/yuicompressor-x.x.x.jar'; 
    Minify_YUICompressor::$tempDir = '/tmp'; 
    return Minify_YUICompressor::minifyJs($js); 
}
$min_serveOptions['minifiers']['application/x-javascript'] = 'yuiJs';

Server-specific Options

You may need to have different options depending on what server you're on. You can do this just how you'd expect:

if ($_SERVER['SERVER_NAME'] == 'myTestingWorkstation') {
    // testing
    $min_allowDebugFlag = true;
    $min_errorLogger    = true;
    $min_enableBuilder  = true;
    $min_cachePath      = 'c:\\WINDOWS\\Temp';
    $min_serveOptions['maxAge'] = 0; // see changes immediately
} else {
    // production
    $min_allowDebugFlag = false;
    $min_errorLogger    = false;
    $min_enableBuilder  = false;
    $min_cachePath      = '/tmp';
    $min_serveOptions['maxAge'] = 86400;
}

Group-specific Options

In "group" requests, $_GET['g'] holds the group key, so you can code based on it:

if (isset($_GET['g'])) {
    switch ($_GET['g']) {
    case 'js' : $min_serveOptions['maxAge'] = 86400 * 7;
                break;
    case 'css': $min_serveOptions['contentTypeCharset'] = 'iso-8859-1';
                break;
    }
}

File/Source-specific Options

See CustomSource.


Sign in to add a comment
Hosted by Google Code