Minify: A JavaScript and CSS Minifier Written in PHP


MatthiasMullie\Minify is a JavaScript and CSS Minifier written in PHP. Usage is straightforward:

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';

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

// save minified file to disk
$minifiedPath = '/path/to/minified/css/file.css';

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

The JavaScript version syntax is the same, just swap out the CSS classes with JS classes.

Install MatthiasMullie\Minify using composer:

composer require matthiasmullie/minify

MatthiasMullie\Minify Source (GitHub) →
Minifier (Demo/Hosted Minify Implementation) →

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.