My personal blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.6 KiB

PHP Css/Js Minifier

Build Status Latest Stable Version Total Downloads License

Composer package to merge and minify a list of Js and Css files.


Using composer

composer require bissolli/php-css-js-minifier

If you don't have composer

You can download it here.

Code Example

Instantiate the class:

$minifier = new \Bissolli\PhpMinifier\Minifier();

Add all the paths of css files that you wish to merge and minify:

// You can load external assets

// Use relative path to add the file

// Full path is also accepted

// Array is also allowed

Add all the paths of js files that you wish to merge and minify:

// As CSS files, you can load full path, relative and external links.
// Array is also allowed

NOTE: You don't need to add Css AND Js files at the same time, it's possible to add only Css or Js files if needed.

Once all the files are added, let's merge and minify all of them:

// Minify and save css and js files
// Output: ./app.min.css & ./app.min.js
$output = $minifier->minify()->output('./', 'app.min');

// Working with Css only
$output = $minifier->minifyCss()->outputCss('./app.min.css');

// Working with Js only
$output = $minifier->minifyJs()->outputJs('./app.min.js');


Released under the MIT license