Minification of JavaScript code and CSS stylesheets.

2.7.0 2023-11-18 16:20 UTC

This package is auto-updated.

Last update: 2024-06-24 20:18:17 UTC



Minify is a PHP library for minification of JavaScript code and CSS stylesheets.

Quick start

Install using Composer, from

composer require wikimedia/minify


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 = '
.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.


See also