Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

README.md

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. На русском

Installation

The preferred way to install this extension is through composer.

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

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

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

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

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

Using without Yii2.

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

About

No description, website, or topics provided.

Resources

Languages

You can’t perform that action at this time.