Introducting Minify. It's just a simple wrapper around jsmin and cssmin to turn it into a Kohana Library. The library handles the minification, setting the correct headers and Gzipping the output for smaller files (based on the rules set out by Yahoo for faster sites).
To finish it off Minify caches output for a configurable time (defaults are 30s on developer sites and 12hrs on production sites) using the Kohana caching library.
Included in the module is a controller (content) which will handle loading JS and CSS files on the fly.
Configuration
Cfg is simple, there are 3 options (2 of which are variable on developer sites).
/*
* Set your minify paths
* these are relative to APPPATH (or, well, MODPATH/SYSPATH for that matter)
*/
$config['path_js'] = 'content/js';
$config['path_css'] = 'content/css';
/*
* File expirey time
* Recommend this is set HIGH (1 yr or more) in production sites
* and super low (10s) for developments sites
* Remember if you screw this up and set it too long you need to change the filename
* because otherwise it wont refresh :)
*/
if(IN_PRODUCTION == TRUE)
{
// 1 yr
$config['expires'] = 31536000;
}
else
{
// 10s
$config['expires'] = 10;
}
/*
* Time in seconds to cache the files
* as these are fairly static files you can properly
* set it quite high for IN_PRODUCTION sites
* Whereas on development sites we want it fairly
* low (and take the performance hit)
* Remember 0 == Cache forever
*/
if(IN_PRODUCTION == TRUE)
{
// 12hrs
$config['cache_lifetime'] = 43200;
}
else
{
// 30s
$config['cache_lifetime'] = 30;
}
Usage
The easiest usage is to just drop in and load the module in the normal way - then use the included content controller to load files from your application directory.
Calls to [site_url]/content/[file_path] will load the relevant file.
Note that you dont need to add the file extension (.css or .js) as the module will add them automatically.
If you want to output a file manually you can use:
$minify = new Minify($method);
echo $minify->compress(implode('/',$arguments));
Get Minify
The package contains the library, css & js drivers, i18n GB & US file, the content controller and config file.
You can download the Zip file here.