Skip to content

adriansuter/psr7-minify-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PSR-7 middleware to minify the response body

Latest Stable Version Build status Coverage Status Total Downloads License

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.

Installation

composer require adriansuter/psr7-minify-middleware

Usage

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'].

In Slim 3:

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']
    )
);

Testing

  • Unit tests: $ vendor/bin/phpunit

About

A PSR7 Minify Middleware that would minify html code

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages