salernolabs/collapser
, (*1)
A PHP media collapser/minifier with CSS and JS extensions. Not really re-inventing the wheel this code was written years ago in my proprietary Chorizo platform. Just moving it out into it's own library. I am fully aware that many developers hate inheritance and protected members/methods. For those offended, I apologize, that's just how this was built., (*2)
Usage
Include this project with composer:, (*3)
composer require salernolabs/collapser
CSS
You can create an instance of the collapser you need, default media (useless), CSS, or Javascript., (*4)
$collapser = new \SalernoLabs\Collapser\CSS();
$collapser->setDeleteComments(true);
$output = $collapser->collapse($input);
If the input CSS is:, (*5)
.helloCSS {
display: none;
}
#somecss {
color: #ffffff;
background: url('/images/whatever.gif');
}
The value of $output would be:, (*6)
.helloCSS{display:none;}
Javascript
$collapser = new \SalernoLabs\Collapser\Javascript();
$collapser->setDeleteComments(true);
$output = $collapser->collapse($input);
If the input Javascript is:, (*7)
/**
Javascript test
*/
var x = 13;
function test(i, j, x)
{
var output = i + j + x;
return output;
}
//Run the function in the alert
var detail = test(1, 2, 3);
alert(detail);
The value of $output should be:, (*8)
var x=13;function test(i, j, x){var output=i+j+x;return output;}var detail=test(1, 2, 3);alert(detail);
Note that it doesn't remove spaces for parameters of functions., (*9)