Clone this repo:
  1. 519c535 build: Upgrade mediawiki/mediawiki-codesniffer to v43.0.0 by Umherirrender · 6 weeks ago master
  2. fb69f21 Merge "JavaScriptMinifier: Change minify() to no longer return false" by jenkins-bot · 8 weeks ago
  3. 1d92731 JavaScriptMinifier: Change minify() to no longer return false by Timo Tijhof · 2 months ago
  4. 6390d8a build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually by James D. Forrester · 3 months ago
  5. 673ad37 build: Upgrade phpunit to 9.6.16 by James D. Forrester · 3 months ago

wikimedia/minify

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!

  • T37492: In CSS, content within quoted strings that looks like source code are sometimes minified.

  • T287631: In CSS, writing a URL over multiple lines with escaped line-breaks is not supported.

Contribute

See also