PHP wrapper to execute uglify-js/clean-css node package or fallback to PHP alternatives

1.0.4 2019-01-16 14:47 UTC

This package is auto-updated.

Last update: 2024-06-16 14:08:10 UTC



Latest Stable Version Build Status StyleCI Test Coverage Code Climate

Simple PHP class to minify both your javascript and css the best existing way (uglify-js for JS, clean-css for CSS) and if node is not available, PHP fallbacks are used instead.


First you need composer if you have not already. Then get the package with composer require nodejs-php-fallback/uglify then require the composer autload in your PHP file if it's not already:


use NodejsPhpFallback\Uglify;

// Require the composer autoload in your PHP file if it's not already.
// You do not need to if you use a framework with composer like Symfony, Laravel, etc.
require 'vendor/autoload.php';

$uglify = new Uglify(array(

// Output to a file:

// Output to the browser:
header('Content-type: text/javascript');
echo $uglify;

Uglify will use js minification by default. If the first source path end with .css or you use ->write() with a path ending with .css, it will switch to CSS mode. Else you can switch manually or get explicitly JS/CSS minified:

echo $uglify; // display minified javascript
echo $uglify; // display minified css

// or
echo $uglify->getMinifiedJs(); // display minified javascript
echo $uglify->getMinifiedCss(); // display minified css

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.