PHPackages                             akankov/twig-compress-html - 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. [Templating &amp; Views](/categories/templating)
4. /
5. akankov/twig-compress-html

ActiveLibrary[Templating &amp; Views](/categories/templating)

akankov/twig-compress-html
==========================

Twig 3 extension wrapping akankov/html-min: provides an html\_min filter and a {% htmlmin %}...{% endhtmlmin %} block tag, plus an optional Symfony bundle.

v1.2.0(1w ago)127.3k↓15.8%MITPHPPHP 8.3.\* || 8.4.\* || 8.5.\*CI passing

Since May 1Pushed 2d ago1 watchersCompare

[ Source](https://github.com/akankov/twig-compress-html)[ Packagist](https://packagist.org/packages/akankov/twig-compress-html)[ Fund](https://ko-fi.com/alekseikankov)[ RSS](/packages/akankov-twig-compress-html/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (34)Versions (6)Used By (0)

twig-compress-html
==================

[](#twig-compress-html)

A Twig 3 extension wrapping [`akankov/html-min`](https://packagist.org/packages/akankov/html-min) — exposes an `html_min` filter and an `{% htmlmin %}...{% endhtmlmin %}` block tag, with an optional Symfony bundle for auto-registration.

Requirements
------------

[](#requirements)

- PHP `8.3.* || 8.4.* || 8.5.*`
- `twig/twig` `^3.0`
- `akankov/html-min` `^2.8`

Install
-------

[](#install)

```
composer require akankov/twig-compress-html
```

Plain Twig usage
----------------

[](#plain-twig-usage)

```
use Akankov\HtmlMin\HtmlMin;
use Akankov\TwigCompressHtml\HtmlMinExtension;
use Akankov\TwigCompressHtml\HtmlMinRuntime;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Twig\RuntimeLoader\FactoryRuntimeLoader;

$twig = new Environment(new FilesystemLoader(__DIR__.'/templates'));
$twig->addExtension(new HtmlMinExtension());
$twig->addRuntimeLoader(new FactoryRuntimeLoader([
    HtmlMinRuntime::class => static fn () => new HtmlMinRuntime(new HtmlMin()),
]));
```

### Filter

[](#filter)

```
{{ rawHtml|html_min }}
```

### Block tag

[](#block-tag)

```
{% htmlmin %}

    {{ content }}

{% endhtmlmin %}
```

The tag captures rendered output (variables are escaped first by Twig's autoescape, then minified), so it's safe to interpolate user data inside.

Symfony usage
-------------

[](#symfony-usage)

Register the bundle in `config/bundles.php`:

```
return [
    // ...
    Akankov\TwigCompressHtml\Bundle\AkankovTwigCompressHtmlBundle::class => ['all' => true],
];
```

Optionally tune `HtmlMin` via `config/packages/akankov_twig_compress_html.yaml`:

```
akankov_twig_compress_html:
    remove_comments: true
    sum_up_whitespace: true
    optimize_attributes: true
    sort_html_attributes: true
    remove_omitted_quotes: false
    minify_inline_css: true
    local_domains: ['example.com']
```

The filter and tag become available in all templates automatically.

### Configuration

[](#configuration)

Every config key is a snake\_case mirror of a property on `Akankov\HtmlMin\Config\MinifierOptions`; the bundle camel-cases them and builds the options object that backs the shared `HtmlMin` service, so:

```
remove_comments: true       # → MinifierOptions::$removeComments
sum_up_whitespace: true     # → MinifierOptions::$sumUpWhitespace
local_domains: ['a.test']   # → MinifierOptions::$localDomains
```

All of the engine's options are accepted — the 26 boolean toggles plus the list options `local_domains`, `special_html_comments_starting_with`, `special_html_comments_ending_with`, `special_script_tags`, and `template_logic_syntax_in_special_script_tags`. Any key you omit falls through to the engine's own default, so the bundle never pins (or drifts from) those defaults. This matches the surface exposed by the Laravel binding's `config/htmlmin.php`.

### Response minification (opt-in)

[](#response-minification-opt-in)

To minify whole `text/html` responses — not just `{% htmlmin %}` blocks — enable the `kernel.response` listener. It is **off by default** (the bundle never adds it to the response pipeline on its own), mirroring the Laravel binding's `MinifyHtmlResponseMiddleware`:

```
akankov_twig_compress_html:
    minify_responses: true
```

Sub-requests, streamed responses, and non-`text/html` responses pass through untouched, so it is safe in front of a mixed JSON / HTML application.

Tests
-----

[](#tests)

```
composer install
vendor/bin/phpunit

# line coverage + floor enforcement (needs pcov or xdebug)
make coverage
```

License
-------

[](#license)

MIT

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance99

Actively maintained with recent releases

Popularity32

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~15 days

Total

3

Last Release

9d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed013f7318c9a6acff086c2c588b6c4ed2089dac3df56d95884367ec79764001?d=identicon)[akankov](/maintainers/akankov)

---

Top Contributors

[![akankov](https://avatars.githubusercontent.com/u/1974569?v=4)](https://github.com/akankov "akankov (16 commits)")

---

Tags

symfonybundletwightmlminifycompresshtml min

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/akankov-twig-compress-html/health.svg)

```
[![Health](https://phpackages.com/badges/akankov-twig-compress-html/health.svg)](https://phpackages.com/packages/akankov-twig-compress-html)
```

###  Alternatives

[nochso/html-compress-twig

Twig extension for compressing HTML and inline CSS/Javascript

79470.5k8](/packages/nochso-html-compress-twig)[voku/html-compress-twig

Twig extension for compressing HTML

282.3M](/packages/voku-html-compress-twig)[yellowskies/qr-code-bundle

Symfony Barcode &amp; QR Code Generator Bundle with Twig extension

36701.5k](/packages/yellowskies-qr-code-bundle)[nucleos/antispam-bundle

This bundle provides some basic features to reduce spam in symfony forms.

52105.1k](/packages/nucleos-antispam-bundle)[eschmar/time-ago-bundle

Provides a simple twig filter for expressing time difference in words.

1751.8k](/packages/eschmar-time-ago-bundle)[mati365/ckeditor5-symfony

CKEditor 5 integration for Symfony

261.9k](/packages/mati365-ckeditor5-symfony)

PHPackages © 2026

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