Simple PSR-7 Middleware that minifies the response body. This middleware can be used to minify the html output.
By default, all textarea
and pre
sections would not be minified (ignored). This can be customized.
composer require adriansuter/psr7-minify-middleware
The constructor of this middleware has two parameters:
- A callback that returns a new object implementing the
Psr\Http\Message\StreamInterface
in order to be able to minify the content. - The html elements (tag names) that should be ignored. This parameter is
optional and defaults to the array
['textarea', 'pre']
.
use AdrianSuter\PSR7\Middleware\Minify;
use Slim\Http\Body;
// Create the application $app
// [...]
$app->add(
new Minify(
function () {
return new Body(fopen('php://temp', 'r+'));
}
)
);
In order to customize the html elements to be ignored, simply add a second parameter to the constructor:
$app->add(
new Minify(
function () {
return new Body(fopen('php://temp', 'r+'));
},
['script', 'textarea', 'pre', 'code']
)
);
- Unit tests:
$ vendor/bin/phpunit