rmrevin\yii\minify\HtmlCompressor::compress PHP Method

compress() public static method

public static compress ( string $data, null | array $options = null ) : string
$data string is either a handle to an open file, or an HTML string
$options null | array key => value array of execute options The possible keys are: - `c` or `no-comments` - removes HTML comments - `s` or `stats` - output filesize savings calculation - `x` or `extra` - perform extra (possibly unsafe) compression operations Example: HtmlCompressor::compress($HtmlCode, $options = ['no-comments' => true])
return string
    public static function compress($data, $options = null)
    {
        return (new static())->htmlCompress($data, $options);
    }

Usage Example

Beispiel #1
1
 /**
  * @throws \rmrevin\yii\minify\Exception
  */
 public function init()
 {
     parent::init();
     $minify_path = $this->minify_path = (string) \Yii::getAlias($this->minify_path);
     if (!file_exists($minify_path)) {
         helpers\FileHelper::createDirectory($minify_path);
     }
     if (!is_readable($minify_path)) {
         throw new Exception('Directory for compressed assets is not readable.');
     }
     if (!is_writable($minify_path)) {
         throw new Exception('Directory for compressed assets is not writable.');
     }
     if (true === $this->compress_output) {
         \Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function (\yii\base\Event $Event) {
             /** @var \yii\web\Response $Response */
             $Response = $Event->sender;
             if ($Response->format === \yii\web\Response::FORMAT_HTML) {
                 if (!empty($Response->data)) {
                     $Response->data = HtmlCompressor::compress($Response->data, $this->compress_options);
                 }
                 if (!empty($Response->content)) {
                     $Response->content = HtmlCompressor::compress($Response->content, $this->compress_options);
                 }
             }
         });
     }
 }
All Usage Examples Of rmrevin\yii\minify\HtmlCompressor::compress