PHPackages                             tetrode/minify - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tetrode/minify

ActiveLibrary

tetrode/minify
==============

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

1.3.55(8y ago)022MITPHPPHP &gt;=5.3.0

Since Oct 19Pushed 8y ago1 watchersCompare

[ Source](https://github.com/tetrode/minify)[ Packagist](https://packagist.org/packages/tetrode/minify)[ Docs](http://www.minifier.org)[ RSS](/packages/tetrode-minify/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (63)Used By (0)

Minify - [minifier.org](https://www.minifier.org)
=================================================

[](#minify---minifierorg)

[![Build status](https://camo.githubusercontent.com/dd09bf64e72243ff7399640cec8e4fe4f47853ddc361cd5ee33a7a283dc0f8fd/68747470733a2f2f6170692e7472617669732d63692e6f72672f6d617474686961736d756c6c69652f6d696e6966792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/matthiasmullie/minify)[![Code coverage](https://camo.githubusercontent.com/25d60a9b8bf0ce4f79c00b18ecdf13c3640a12b68ab375fee502daaf2138d79c/687474703a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6d617474686961736d756c6c69652f6d696e6966792e737667)](https://codecov.io/github/matthiasmullie/minify)[![Code quality](https://camo.githubusercontent.com/a7fef15d1e857de9c54eacdd84343a1daade5644fa901ee2ef55605869bce5cb/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d617474686961736d756c6c69652f6d696e6966792e737667)](https://scrutinizer-ci.com/g/matthiasmullie/minify)[![Latest version](https://camo.githubusercontent.com/96ee513b21a45477a23aca769163af2112be342ad1fe4999da7ef44f455c0f8e/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617474686961736d756c6c69652f6d696e6966792e737667)](https://packagist.org/packages/matthiasmullie/minify)[![Downloads total](https://camo.githubusercontent.com/dabc116477984079fd536b989f9c6a064a0696d2de27a486c6f542d1750b3c60/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617474686961736d756c6c69652f6d696e6966792e737667)](https://packagist.org/packages/matthiasmullie/minify)[![License](https://camo.githubusercontent.com/a6bac5c44378cfb202b3a9b19c0733235fe8bea042b3b99be71b251b188d1a2e/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d617474686961736d756c6c69652f6d696e6966792e737667)](https://github.com/matthiasmullie/minify/blob/master/LICENSE)

Removes whitespace, strips comments, combines files (incl. `@import` statements and small assets in CSS files), and optimizes/shortens a few common programming patterns, such as:

**JavaScript**

- `object['property']` -&gt; `object.property`
- `true`, `false` -&gt; `!0`, `!1`
- `while(true)` -&gt; `for(;;)`

**CSS**

- `@import url("http://path")` -&gt; `@import "http://path"`
- `#ff0000`, `#ff00ff` -&gt; `red`, `#f0f`
- `-0px`, `50.00px` -&gt; `0`, `50px`
- `bold` -&gt; `700`
- `p {}` -&gt; removed

And it comes with a huge test suite.

Usage
-----

[](#usage)

### CSS

[](#css)

```
use MatthiasMullie\Minify;

$sourcePath = '/path/to/source/css/file.css';
$minifier = new Minify\CSS($sourcePath);

// we can even add another file, they'll then be
// joined in 1 output file
$sourcePath2 = '/path/to/second/source/css/file.css';
$minifier->add($sourcePath2);

// or we can just add plain CSS
$css = 'body { color: #000000; }';
$minifier->add($css);

// save minified file to disk
$minifiedPath = '/path/to/minified/css/file.css';
$minifier->minify($minifiedPath);

// or just output the content
echo $minifier->minify();
```

### JS

[](#js)

```
// just look at the CSS example; it's exactly the same, but with the JS class & JS files :)
```

Methods
-------

[](#methods)

Available methods, for both CSS &amp; JS minifier, are:

### \_\_construct(/\* overload paths \*/)

[](#__construct-overload-paths-)

The object constructor accepts 0, 1 or multiple paths of files, or even complete CSS/JS content, that should be minified. All CSS/JS passed along, will be combined into 1 minified file.

```
use MatthiasMullie\Minify;
$minifier = new Minify\JS($path1, $path2);
```

### add($path, /\* overload paths \*/)

[](#addpath--overload-paths-)

This is roughly equivalent to the constructor.

```
$minifier->add($path3);
$minifier->add($js);
```

### minify($path)

[](#minifypath)

This will minify the files' content, save the result to $path and return the resulting content. If the $path parameter is omitted, the result will not be written anywhere.

*CAUTION: If you have CSS with relative paths (to imports, images, ...), you should always specify a target path! Then those relative paths will be adjusted in accordance with the new path.*

```
$minifier->minify('/target/path.js');
```

### gzip($path, $level)

[](#gzippath-level)

Minifies and optionally saves to a file, just like `minify()`, but it also `gzencode()`s the minified content.

```
$minifier->gzip('/target/path.js');
```

### setMaxImportSize($size) *(CSS only)*

[](#setmaximportsizesize-css-only)

The CSS minifier will automatically embed referenced files (like images, fonts, ...) into the minified CSS, so they don't have to be fetched over multiple connections.

However, for really large files, it's likely better to load them separately (as it would increase the CSS load time if they were included.)

This method allows the max size of files to import into the minified CSS to be set (in kB). The default size is 5.

```
$minifier->setMaxImportSize(10);
```

### setImportExtensions($extensions) *(CSS only)*

[](#setimportextensionsextensions-css-only)

The CSS minifier will automatically embed referenced files (like images, fonts, ...) into minified CSS, so they don't have to be fetched over multiple connections.

This methods allows the type of files to be specified, along with their data:mime type.

The default embedded file types are gif, png, jpg, jpeg, svg &amp; woff.

```
$extensions = array(
    'gif' => 'data:image/gif',
    'png' => 'data:image/png',
);

$minifier->setImportExtensions($extensions);
```

Installation
------------

[](#installation)

Simply add a dependency on matthiasmullie/minify to your composer.json file if you use [Composer](https://getcomposer.org/) to manage the dependencies of your project:

```
composer require matthiasmullie/minify
```

Although it's recommended to use Composer, you can actually [include these files](https://github.com/matthiasmullie/minify/issues/83) anyway you want.

Try it
------

[](#try-it)

Simply try it out online at .

License
-------

[](#license)

Minify is [MIT](http://opensource.org/licenses/MIT) licensed.

Challenges
----------

[](#challenges)

If you're interested in learning some of the harder technical challenges I've encountered building this, you probably want to take a look at [what I wrote about it](http://www.mullie.eu/dont-build-your-own-minifier/) on my blog.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 88.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~10 days

Total

61

Last Release

3124d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.2.0

1.1.0PHP &gt;=5.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f035a4a6d4b641f8d3575749f02259aae405c470bacc1573602822e2a5bbc09a?d=identicon)[tetrode](/maintainers/tetrode)

---

Top Contributors

[![matthiasmullie](https://avatars.githubusercontent.com/u/312776?v=4)](https://github.com/matthiasmullie "matthiasmullie (310 commits)")[![GinoPane](https://avatars.githubusercontent.com/u/3897579?v=4)](https://github.com/GinoPane "GinoPane (20 commits)")[![woutervanvliet](https://avatars.githubusercontent.com/u/123354?v=4)](https://github.com/woutervanvliet "woutervanvliet (4 commits)")[![roggeo](https://avatars.githubusercontent.com/u/7748483?v=4)](https://github.com/roggeo "roggeo (3 commits)")[![mattleff](https://avatars.githubusercontent.com/u/120155?v=4)](https://github.com/mattleff "mattleff (3 commits)")[![unscrewed1](https://avatars.githubusercontent.com/u/268868799?v=4)](https://github.com/unscrewed1 "unscrewed1 (2 commits)")[![tetrode](https://avatars.githubusercontent.com/u/5877361?v=4)](https://github.com/tetrode "tetrode (2 commits)")[![throup](https://avatars.githubusercontent.com/u/1216362?v=4)](https://github.com/throup "throup (2 commits)")[![vladimmi](https://avatars.githubusercontent.com/u/891830?v=4)](https://github.com/vladimmi "vladimmi (1 commits)")[![GordonLesti](https://avatars.githubusercontent.com/u/1677744?v=4)](https://github.com/GordonLesti "GordonLesti (1 commits)")[![kaittodesk](https://avatars.githubusercontent.com/u/6755852?v=4)](https://github.com/kaittodesk "kaittodesk (1 commits)")[![alexcorvi](https://avatars.githubusercontent.com/u/12078588?v=4)](https://github.com/alexcorvi "alexcorvi (1 commits)")[![smxsm](https://avatars.githubusercontent.com/u/1737182?v=4)](https://github.com/smxsm "smxsm (1 commits)")

---

Tags

javascriptcssJSminifyminifier

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/tetrode-minify/health.svg)

```
[![Health](https://phpackages.com/badges/tetrode-minify/health.svg)](https://phpackages.com/packages/tetrode-minify)
```

###  Alternatives

[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k30.5M336](/packages/matthiasmullie-minify)[stolz/assets

An ultra-simple-to-use assets management library

296519.2k8](/packages/stolz-assets)[sensiolabs/minify-bundle

Assets Minifier (CSS, JS) for Symfony &amp; Minify integration in Asset Mapper

5694.9k1](/packages/sensiolabs-minify-bundle)[rmrevin/yii2-minify-view

Yii2 View component with auto minification css &amp; js in runtime

194302.3k7](/packages/rmrevin-yii2-minify-view)[tholu/php-packer

A PHP version of Packer, JavaScript obfuscation library originally created by Dean Edwards

137441.2k5](/packages/tholu-php-packer)[middlewares/minifier

Middleware to minify Html, CSS and Javascript responses

1729.1k2](/packages/middlewares-minifier)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
