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

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

jorisros/html-compress-twig
===========================

Twig extension for compressing HTML and inline CSS/Javascript

2.0.1(9y ago)06ISCPHP

Since Oct 5Pushed 5y agoCompare

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

READMEChangelogDependencies (3)Versions (7)Used By (0)

nochso/html-compress-twig extension
===================================

[](#nochsohtml-compress-twig-extension)

[![Latest Stable Version](https://camo.githubusercontent.com/b137ad05125e6d72f255e0339cd6c1cd60c1a7ef431e8114f747be1cb282631c/68747470733a2f2f706f7365722e707567782e6f72672f6e6f6368736f2f68746d6c2d636f6d70726573732d747769672f762f737461626c65)](https://packagist.org/packages/nochso/html-compress-twig)[![License](https://camo.githubusercontent.com/66162d1bdc63d8f40a70148f44501ee2b7af718a8dcba166aa9fb2fa4d4ad6a2/68747470733a2f2f706f7365722e707567782e6f72672f6e6f6368736f2f68746d6c2d636f6d70726573732d747769672f6c6963656e7365)](LICENSE)[![Build Status](https://camo.githubusercontent.com/ffbac52b3d975a6d6862f612c12cdae2d45eac5abd1b501d2e2617e46157bdbb/68747470733a2f2f7472617669732d63692e6f72672f6e6f6368736f2f68746d6c2d636f6d70726573732d747769672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/nochso/html-compress-twig)

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

Currently supported Twig features are:

- Tag
    - `{% htmlcompress %} ... {% endhtmlcompress %}`
- Function
    - `{{ htmlcompress('some html') }}`
- Filter
    - `{{ content|markdown|htmlcompress }}`

Any HTML, inline CSS and Javascript will be compressed.

- [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 nochso/html-compress-twig
    ```

Usage
-----

[](#usage)

First register the extension with Twig:

```
$twig = new Twig_Environment($loader);
$twig->addExtension(new \nochso\HtmlCompressTwig\Extension());
```

Then use it in your templates:

```
{% htmlcompress %}{% endhtmlcompress %}
{{ htmlcompress(' ') }}
{{ ' '|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 parameter `$forceCompression`. When true, this will force compression regardless of Twig's `debug` setting. It defaults to false when omitted.

```
// Enable compression regardless of Twig's debug setting
$twig->addExtension(new \nochso\HtmlCompressTwig\Extension(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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 94.7% 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 ~122 days

Total

5

Last Release

3378d ago

Major Versions

0.1 → 1.0.02016-01-14

1.0.1 → 2.0.02016-12-03

### Community

Maintainers

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

---

Top Contributors

[![nochso](https://avatars.githubusercontent.com/u/6887618?v=4)](https://github.com/nochso "nochso (36 commits)")[![jorisros](https://avatars.githubusercontent.com/u/752283?v=4)](https://github.com/jorisros "jorisros (2 commits)")

---

Tags

twigjavascriptcsshtmlminifycompressextension

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[nochso/html-compress-twig

Twig extension for compressing HTML and inline CSS/Javascript

84468.6k7](/packages/nochso-html-compress-twig)[voku/html-compress-twig

Twig extension for compressing HTML

252.3M](/packages/voku-html-compress-twig)[twig/string-extra

A Twig extension for Symfony String

21946.0M132](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

23018.5M53](/packages/twig-cssinliner-extra)[twig/markdown-extra

A Twig extension for Markdown

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

A Twig extension for HTML

777.6M41](/packages/twig-html-extra)

PHPackages © 2026

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