2012-10-09 12:48:24 +02:00
# Minify
2012-10-09 02:29:59 -07:00
2014-10-08 17:03:29 +02:00
[](https://travis-ci.org/matthiasmullie/minify)
[](https://packagist.org/packages/matthiasmullie/minify)
[](https://packagist.org/packages/matthiasmullie/minify)
[](https://github.com/matthiasmullie/minify/blob/master/LICENSE)
2012-10-09 12:48:24 +02:00
## Methods
Available methods, for both CSS & JS minifier, are:
### __construct(/* overload paths */)
The object constructor accepts 0, 1 or multiple paths of files, or even complete CSS content, that should be minified.
All CSS passed along, will be combined into 1 minified file.
2013-04-14 23:38:24 +02:00
use MatthiasMullie\Minify;
$minifier = new Minify\CSS($path1, $path2);
2012-10-09 12:48:24 +02:00
### add($path, /* overload paths */)
This is roughly equivalent to the constructor.
$minifier->add($path3);
$minifier->add($css);
2014-10-08 12:56:41 +02:00
### minify($path)
2012-10-09 12:48:24 +02:00
This will minify the files' content, save the result to $path and return the resulting content.
If the $path parameter is false, the result will not be written anywhere. CAUTION: Only use this for "simple" CSS: if no target directory ($path) is known, relative uris to e.g. images can not be fixed!
2013-12-26 23:59:56 +01:00
$minifier->minify('/target/path.css');
2012-10-09 12:48:24 +02:00
## Example usage
$file1 = '/path/to/file1.css';
$file2 = '/yet/another/path/to/file2.css';
$file3 = '/and/another/path/to/file3.css';
$css = 'body { color: #000000 ; }';
// constructor can be overloaded with multiple files
2013-04-14 23:38:24 +02:00
$minifier = new Minify\CSS($file1, $file2);
2012-10-09 12:48:24 +02:00
// or files can be added individually
$minifier->add($file3);
// or even css content can be loaded
$minifier->add($css);
2013-12-26 23:59:56 +01:00
// minify & write to file
$minifier->minify('/target/path.css');
2012-10-09 12:48:24 +02:00
## License
2013-04-15 15:09:28 +03:00
Minify is [MIT ](http://opensource.org/licenses/MIT ) licensed.
2013-12-26 16:03:20 +01:00
## CLI script
[Baki Goxhaj ](https://github.com/banago ) developed a [CLI tool ](https://github.com/banago/CLI-Minify ) using this library - could be useful to automate minification of your project's CSS/JS files in e.g. some build or deployment script.