bissolli / php-css-js-minifier
A PHP Class to merge and minify CSS and JavaScript files.
Installs: 2 275
Dependents: 2
Suggesters: 0
Security: 0
Stars: 8
Watchers: 3
Forks: 4
Open Issues: 1
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ~5.6
This package is auto-updated.
Last update: 2024-10-23 14:22:08 UTC
README
Composer package to merge and minify a list of Js and Css files.
Installation
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 $minifier->addCssFile('https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap-reboot.css'); // Use relative path to add the file $minifier->addCssFile('./data/style1.css'); // Full path is also accepted $minifier->addCssFile('/{FULL_PATH}/php-css-js-minifier/examples/data/style2.css'); // Array is also allowed $minifier->addCssFile([ 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap-reboot.css', './data/style1.css', '/{FULL_PATH}/php-css-js-minifier/examples/data/style2.css' ]);
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 $minifier->addJsFile('./data/script1.js'); $minifier->addJsFile('/{FULL_PATH}/php-css-js-minifier/examples/data/script2.js');
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');
License
Released under the MIT license