| 1 |
# wikimedia/minify |
| 2 |
|
| 3 |
Minify is a PHP library for minification of JavaScript code and CSS stylesheets. |
| 4 |
|
| 5 |
## Quick start |
| 6 |
|
| 7 |
Install using [Composer](https://getcomposer.org/), from [Packagist.org](https://packagist.org/packages/wikimedia/minify): |
| 8 |
|
| 9 |
``` |
| 10 |
composer require wikimedia/minify |
| 11 |
``` |
| 12 |
|
| 13 |
## Usage |
| 14 |
|
| 15 |
```php |
| 16 |
use Wikimedia\Minify\JavaScriptMinifier; |
| 17 |
|
| 18 |
$input = ' |
| 19 |
/** |
| 20 |
* @param a |
| 21 |
* @param b |
| 22 |
*/ |
| 23 |
function sum(a, b) { |
| 24 |
// Add it up! |
| 25 |
return a + b; |
| 26 |
} |
| 27 |
'; |
| 28 |
|
| 29 |
$output = JavaScriptMinifier::minify( $input ); |
| 30 |
// Result: |
| 31 |
// function sum(a,b){return a+b;} |
| 32 |
``` |
| 33 |
|
| 34 |
```php |
| 35 |
use Wikimedia\Minify\CSSMin; |
| 36 |
|
| 37 |
$input = ' |
| 38 |
.foo, |
| 39 |
.bar { |
| 40 |
/* comment */ |
| 41 |
prop: value; |
| 42 |
} |
| 43 |
'; |
| 44 |
|
| 45 |
$output = CSSMin::minify( $input ); |
| 46 |
// Result: |
| 47 |
// .foo,.bar{prop:value} |
| 48 |
``` |
| 49 |
|
| 50 |
## Known limitations |
| 51 |
|
| 52 |
The following trade-offs were made for improved runtime performance and code |
| 53 |
simplicity. If they cause problems in real-world applications without trivial |
| 54 |
workarounds, please let us know! |
| 55 |
|
| 56 |
* [T37492](https://phabricator.wikimedia.org/T37492): In CSS, content within quoted |
| 57 |
strings that looks like source code are sometimes minified. |
| 58 |
|
| 59 |
* [T287631](https://phabricator.wikimedia.org/T287631): In CSS, writing a URL |
| 60 |
over multiple lines with escaped line-breaks is not supported. |
| 61 |
|
| 62 |
## Contribute |
| 63 |
|
| 64 |
* Issue tracker: <https://phabricator.wikimedia.org/tag/wikimedia-minify/> |
| 65 |
* Source code: <https://gerrit.wikimedia.org/g/mediawiki/libs/Minify> |
| 66 |
* Submit patches via Gerrit: <https://www.mediawiki.org/wiki/Developer_account> |
| 67 |
|
| 68 |
## See also |
| 69 |
|
| 70 |
* High-level documentation: <https://www.mediawiki.org/wiki/ResourceLoader/Architecture> |