wikimedia / minify
Minification of JavaScript code and CSS stylesheets.
2.11.0
2026-06-26 16:30 UTC
Requires
- php: >=8.1
- ext-fileinfo: *
- ext-mbstring: *
- pear/net_url2: ~2.2.2
Requires (Dev)
- mck89/peast: ^1.16
- mediawiki/mediawiki-codesniffer: 51.0.0
- mediawiki/mediawiki-phan-config: 0.20.0
- mediawiki/minus-x: 2.0.1
- ockcyp/covers-validator: 1.7.0
- php-parallel-lint/php-console-highlighter: 1.0.0
- php-parallel-lint/php-parallel-lint: 1.4.0
- phpunit/phpunit: 10.5.63
- wikimedia/testing-access-wrapper: ~4.0.0
README
Minify is a PHP library for minification of JavaScript code and CSS stylesheets.
Quick start
Install using Composer, from Packagist.org:
composer require wikimedia/minify
Usage
use Wikimedia\Minify\JavaScriptMinifier; $input = ' /** * @param a * @param b */ function sum(a, b) { // Add it up! return a + b; } '; $output = JavaScriptMinifier::minify( $input ); // Result: // function sum(a,b){return a+b;}
use Wikimedia\Minify\CSSMin; $input = ' .foo, .bar { /* comment */ prop: value; } '; $output = CSSMin::minify( $input ); // Result: // .foo,.bar{prop:value}
Known limitations
The following trade-offs were made for improved runtime performance and code simplicity. If they cause problems in real-world applications without trivial workarounds, please let us know!
- In CSS, content within quoted strings that looks like source code is sometimes minified (T37492).
- In CSS, writing a URL over multiple lines with escaped line-breaks is not supported (T287631).
- In JS, certain multibyte spaces are not supported as whitespace in source code (including U+00A0 No Break Space NBSP, U+2028 Line Separator, and U+2029 Paragraph Separator) and may produce invalid output. Note that these and other Unicode multibyte characters are fully supported in strings, identifiers, and regexes (change 1278715).
Contribute
- Issue tracker: https://phabricator.wikimedia.org/tag/wikimedia-minify/
- Source code: https://gerrit.wikimedia.org/g/mediawiki/libs/Minify
- Submit patches via Gerrit: https://www.mediawiki.org/wiki/Developer_account
- To run tests:
composer update, thencomposer test
See also
- High-level documentation: https://www.mediawiki.org/wiki/ResourceLoader/Architecture