PHPackages                             voku/html-compress-twig - 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. voku/html-compress-twig

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

voku/html-compress-twig
=======================

Twig extension for compressing HTML

4.0.2(5y ago)252.3M—7.9%7[2 PRs](https://github.com/voku/html-compress-twig/pulls)ISCPHPPHP &gt;=7.0.0

Since Mar 18Pushed 3y ago2 watchersCompare

[ Source](https://github.com/voku/html-compress-twig)[ Packagist](https://packagist.org/packages/voku/html-compress-twig)[ RSS](/packages/voku-html-compress-twig/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (11)Used By (0)

[![Build Status](https://camo.githubusercontent.com/554121917170454a6ad0ce8db052f1d55f20499a9517002bc7ce250de6051765/68747470733a2f2f7472617669732d63692e6f72672f766f6b752f68746d6c2d636f6d70726573732d747769672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/voku/html-compress-twig)[![Coverage Status](https://camo.githubusercontent.com/51136ad01275bb9f9fd5ba2169674d40503f014fc8100b6c70678e22c18f2cbe/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f766f6b752f68746d6c2d636f6d70726573732d747769672f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/voku/html-compress-twig?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2aa1fd0bea4477ce107f1266f44e324ec7befb69c6576a842414f3cd0d1ed5f6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f766f6b752f68746d6c2d636f6d70726573732d747769672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/voku/html-compress-twig/?branch=master)[![Codacy Badge](https://camo.githubusercontent.com/4f11f5d98d5b371d691fe02b6e65dc91ffcbf8afc1b36765c79b0bf8189b99c5/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3034393765316635626532643433613038633061313038646337313932323837)](https://www.codacy.com/app/voku/html-compress-twig?utm_source=github.com&utm_medium=referral&utm_content=voku/html-compress-twig&utm_campaign=Badge_Grade)[![SensioLabsInsight](https://camo.githubusercontent.com/483964cce9d631706b6d6f7540c17969113b13b54fad669faee0558311114295/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f34306436333138612d363466632d343932372d383433382d6335376230663534363934392f6d696e692e706e67)](https://insight.sensiolabs.com/projects/40d6318a-64fc-4927-8438-c57b0f546949)[![Latest Stable Version](https://camo.githubusercontent.com/9ac9f4e548516d8f86a7d253c40ea3006b748a7b312d956b8b9b48d70338d3e6/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f68746d6c2d636f6d70726573732d747769672f762f737461626c65)](https://packagist.org/packages/voku/html-compress-twig)[![Total Downloads](https://camo.githubusercontent.com/7e81cd7a4a8465120ae3bef94d02e4e1158c91fcdf060cddb75cd1b1643776da/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f68746d6c2d636f6d70726573732d747769672f646f776e6c6f616473)](https://packagist.org/packages/voku/html-compress-twig)[![Latest Unstable Version](https://camo.githubusercontent.com/a89a6dc00e61eab1af09dfbaf87b1a717b38dca86457eedddbd5ade45f07567b/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f68746d6c2d636f6d70726573732d747769672f762f756e737461626c65)](https://packagist.org/packages/voku/html-compress-twig)[![License](https://camo.githubusercontent.com/d5a98a4c906c3cf91cf45d0fe7f37549f1bcba4ec9e353ce2f44affa452893d5/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f68746d6c2d636f6d70726573732d747769672f6c6963656e7365)](https://packagist.org/packages/voku/html-compress-twig)

🗜️ HtmlMin for Twig: HTML Compressor and Minifier
=================================================

[](#clamp-htmlmin-for-twig-html-compressor-and-minifier)

Description
-----------

[](#description)

A [Twig](http://twig.sensiolabs.org/) extension for [voku/HtmlMin](https://github.com/voku/HtmlMin).

Currently supported Twig features are:

- Tag

    - `{% htmlcompress %} bar {% endhtmlcompress %}`
- Function

    - `{{ htmlcompress(' bar') }}`
- Filter

    - `{{ ' bar' | htmlcompress }}`
- [Installation](#installation)
- [Usage](#usage)
- [History](#history)
- [License](#license)

Installation
------------

[](#installation)

1. Install and use [composer](https://getcomposer.org/doc/00-intro.md) in your project.
2. Require this package via composer:

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

Usage
-----

[](#usage)

First register the extension with Twig:

```
use voku\helper\HtmlMin;
use voku\twig\MinifyHtmlExtension;

$twig = new \Twig\Environment($loader);
$minifier = new HtmlMin();
$twig->addExtension(new MinifyHtmlExtension($minifier));
```

### Register extension in symfony 4

[](#register-extension-in-symfony-4)

Specifying HtmlMin is needed for the autowiring.

```
    voku\helper\HtmlMin:
        tags:
            - { name: HtmlMin }

    voku\twig\MinifyHtmlExtension:
        arguments:
            $forceCompression: false
        tags:
            - { name: twig.extension }
```

Then use it in your templates:

```
{% htmlcompress %} bar {% endhtmlcompress %}
{{ htmlcompress(' bar') }}
{{ ' bar' | htmlcompress }}

```

**Compression is disabled by Twig's `debug` setting.** This is to make development easier, however you can always override it.

The constructor of this extension takes a boolean as second parameter `$forceCompression`. When true, this will force compression regardless of Twig's `debug` setting. It defaults to false when omitted.

```
$twig->addExtension(new MinifyHtmlExtension($minifier, true));
```

History
-------

[](#history)

See [CHANGELOG](CHANGELOG.md) for the full history of changes.

License
-------

[](#license)

This project is licensed under the ISC license which is MIT/GPL compatible and FSF/OSI approved. See the [LICENSE](LICENSE) file for the full license text.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity51

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 52.9% 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 ~198 days

Recently: every ~282 days

Total

8

Last Release

1959d ago

Major Versions

1.0.2 → 2.0.02017-12-03

2.0.0 → 3.0.02017-12-22

3.0.0 → 4.0.02019-11-24

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

2.0.0PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6456fe693db197c458272cb758bf78958bc7d3e787ccd59db4bf3cf41654316a?d=identicon)[voku](/maintainers/voku)

---

Top Contributors

[![nochso](https://avatars.githubusercontent.com/u/6887618?v=4)](https://github.com/nochso "nochso (36 commits)")[![voku](https://avatars.githubusercontent.com/u/264695?v=4)](https://github.com/voku "voku (29 commits)")[![Mondane](https://avatars.githubusercontent.com/u/1150272?v=4)](https://github.com/Mondane "Mondane (2 commits)")[![cjhaas](https://avatars.githubusercontent.com/u/7748460?v=4)](https://github.com/cjhaas "cjhaas (1 commits)")

---

Tags

hacktoberfesthtml-minifierminifyphptwig-extensiontwightmlminifycompressextension

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[nochso/html-compress-twig

Twig extension for compressing HTML and inline CSS/Javascript

84468.6k8](/packages/nochso-html-compress-twig)[twig/string-extra

A Twig extension for Symfony String

22046.0M133](/packages/twig-string-extra)[twig/markdown-extra

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)[twig/html-extra

A Twig extension for HTML

787.6M41](/packages/twig-html-extra)[fitztrev/laravel-html-minify

Minifies the HTML output of Laravel 4 applications

414211.4k](/packages/fitztrev-laravel-html-minify)[twig/cache-extra

A Twig extension for Symfony Cache

392.1M20](/packages/twig-cache-extra)

PHPackages © 2026

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