PHPackages                             adriansuter/psr7-minify-middleware - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. adriansuter/psr7-minify-middleware

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

adriansuter/psr7-minify-middleware
==================================

PSR-7 Middleware that minifies the response body (HTML Minify).

v0.3(7y ago)173MITPHPPHP &gt;=5.5.0

Since Oct 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/adriansuter/psr7-minify-middleware)[ Packagist](https://packagist.org/packages/adriansuter/psr7-minify-middleware)[ Docs](http://github.com/adriansuter/psr7-minify-middleware)[ RSS](/packages/adriansuter-psr7-minify-middleware/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

PSR-7 middleware to minify the response body
============================================

[](#psr-7-middleware-to-minify-the-response-body)

[![Latest Stable Version](https://camo.githubusercontent.com/3e8329abb90ba6dbc2a7e3b339dbecc68d01415309748b684909cdeb5a037d86/68747470733a2f2f706f7365722e707567782e6f72672f61647269616e73757465722f707372372d6d696e6966792d6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/adriansuter/psr7-minify-middleware)[![Build status](https://camo.githubusercontent.com/5a3367d65f5ce63f1be81fe495d833c57e42a1eeab1a9e547868e6fb86a19724/68747470733a2f2f7472617669732d63692e6f72672f61647269616e73757465722f707372372d6d696e6966792d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/adriansuter/psr7-minify-middleware)[![Coverage Status](https://camo.githubusercontent.com/04370e753f7b0841102815cbe7223422b1b4e5fb0c251abbd8c73c7de3e57b7d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f61647269616e73757465722f707372372d6d696e6966792d6d6964646c65776172652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/adriansuter/psr7-minify-middleware?branch=master)[![Total Downloads](https://camo.githubusercontent.com/ae13b979aed0a3d4800b41a7567504ecaf49a94e6bf3da9de640cfd5cc744812/68747470733a2f2f706f7365722e707567782e6f72672f61647269616e73757465722f707372372d6d696e6966792d6d6964646c65776172652f646f776e6c6f616473)](https://packagist.org/packages/adriansuter/psr7-minify-middleware)[![License](https://camo.githubusercontent.com/51ea5ca88f772f2a44fd8ad391678478877b2985816cbf64a792adb4a5a3b8e7/68747470733a2f2f706f7365722e707567782e6f72672f61647269616e73757465722f707372372d6d696e6966792d6d6964646c65776172652f6c6963656e7365)](https://packagist.org/packages/adriansuter/psr7-minify-middleware)

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
------------

[](#installation)

`composer require adriansuter/psr7-minify-middleware`

Usage
-----

[](#usage)

The constructor of this middleware has two parameters:

- A callback that returns a new object implementing the [`Psr\Http\Message\StreamInterface`](https://github.com/php-fig/http-message/blob/master/src/StreamInterface.php)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:

[](#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
-------

[](#testing)

- Unit tests: `$ vendor/bin/phpunit`

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~311 days

Total

4

Last Release

2618d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ff41e3338b4e847e43441cf54099844bae3c789b409a378f8f6374d37ba1057?d=identicon)[adriansuter](/maintainers/adriansuter)

---

Top Contributors

[![adriansuter](https://avatars.githubusercontent.com/u/3974990?v=4)](https://github.com/adriansuter "adriansuter (26 commits)")

---

Tags

middlewarepsr7minify

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adriansuter-psr7-minify-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/adriansuter-psr7-minify-middleware/health.svg)](https://phpackages.com/packages/adriansuter-psr7-minify-middleware)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k34](/packages/neuron-core-neuron-ai)[spatie/laravel-export

Create a static site bundle from a Laravel app

672139.5k6](/packages/spatie-laravel-export)[razorpay/ifsc

Razorpay IFSC Codes Library

385204.4k](/packages/razorpay-ifsc)[anthropic-ai/sdk

Anthropic PHP SDK

160372.1k15](/packages/anthropic-ai-sdk)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35729.6k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
