PHPackages                             zabachok/yii2-htmlcompressor - 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. zabachok/yii2-htmlcompressor

ActiveYii2-extension

zabachok/yii2-htmlcompressor
============================

Smart HTML compressor

v1(9y ago)042MITPHP

Since Jun 1Pushed 9y ago1 watchersCompare

[ Source](https://github.com/zabachok/yii2-htmlcompressor)[ Packagist](https://packagist.org/packages/zabachok/yii2-htmlcompressor)[ RSS](/packages/zabachok-yii2-htmlcompressor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Compressing HTML before submit to client
========================================

[](#compressing-html-before-submit-to-client)

HTML compressor. This component allows you to compress the HTML-code. If you want it is possible not to compress the contents in `script` and `code` tags. [На русском](http://zabachok.net/repositories/htmlcompressor)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist zabachok/yii2-htmlcompressor "*"

```

or add

```
"zabachok/yii2-htmlcompressor": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by :

### By View component

[](#by-view-component)

In your config file in components:

```
'view' => [
	'class' => '\zabachok\htmlcompressor\View',
	'compress' => YII_ENV_DEV ? false : true,
	'compressCode' => false,
	'compressScript' => false
],
```

### By event

[](#by-event)

In your config file in components:

```
'response' => [
	'on beforeSend' => function ($event)
	{
		/** @var $event yii\base\ViewEvent */
		$response = $event->sender;
		$compressor = new \zabachok\htmlcompressor\HtmlCompressor(false, false);
		$response->data = $compressor->make($response->data);
	},
],
```

### By behavior

[](#by-behavior)

If you already have custom `View` component, you can use behavior.

```
class View extends \yii\web\View
{
    public function behaviors()
    {
        return [
            [
                'class' => HtmlCompressorBehavior::className(),
                'compress' => true,
                'compressScript' => true,
                'compressCode' => true,
            ],
        ];
    }
    ...
}
```

### Withoit Yii2

[](#withoit-yii2)

Using without Yii2.

```
$compressor = new HtmlCompressor();
$result = $compressor->make($html);
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Unknown

Total

1

Last Release

3630d ago

### Community

Maintainers

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

---

Tags

compressionlibraryhtmlyii2extension

### Embed Badge

![Health badge](/badges/zabachok-yii2-htmlcompressor/health.svg)

```
[![Health](https://phpackages.com/badges/zabachok-yii2-htmlcompressor/health.svg)](https://phpackages.com/packages/zabachok-yii2-htmlcompressor)
```

###  Alternatives

[kartik-v/yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.

1605.5M84](/packages/kartik-v-yii2-mpdf)[fedemotta/yii2-widget-datatables

DataTables widget for Yii2

34179.4k1](/packages/fedemotta-yii2-widget-datatables)[bizley/contenttools

ContentTools editor implementation for Yii 2.

8016.7k](/packages/bizley-contenttools)[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k46](/packages/skeeks-cms)[jodit/yii2-jodit

Jodit - awesome WYSIWYG Editor like widget for Yii2

1621.5k](/packages/jodit-yii2-jodit)[phpnt/yii2-export

Yii2 It saves data in xls, csv, word, html, pdf files.

158.9k](/packages/phpnt-yii2-export)

PHPackages © 2026

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