zabachok / yii2-htmlcompressor
Smart HTML compressor
Installs: 42
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-12-11 17:33:53 UTC
README
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);