The extension is a filter to compress the HTML output - to reduce bandwidth.
The filter offers two compression methods:
- GZIP compression
- Trim leading white space and blank lines from HTML output. But does not affect pre, script or textarea blocks.
Heads up: The GZIP compression is turned off for old buggy IE's (< IE7).
Requirements ¶
- Yii 1.1.10 or above...(could work with older versions)
- tested with IE7-9, Firefox 13, Chromium, Safari 5.1
Installation ¶
- Extract the release file under protected/filters
- put in a controller code blocks like the following...
Usage ¶
See the following code example:
GZIP for all actions
/**
* @return array action filters
*/
public function filters()
{
return array(
array(
'application.filters.html.ECompressHtmlFilter',
'gzip' => (YII_DEBUG ? false : true),
'doStripNewlines' => (YII_DEBUG ? false : true),
'actions' => '*'
),
);
}
GZIP only for index & admin action in controller with CRUD actions
/**
* @return array action filters
*/
public function filters()
{
return array(
array(
'application.filters.html.ECompressHtmlFilter',
'gzip' => (YII_DEBUG ? false : true),
'doStripNewlines' => (YII_DEBUG ? false : true),
'actions' => 'index, admin'
),
);
}
Trim leading white space, blank lines & new lines from HTML output for all action
/**
* @return array action filters
*/
public function filters()
{
return array(
array(
'application.filters.html.ECompressHtmlFilter',
'gzip' => false,
'actions' => 'ALL'
),
);
}
Nothing will compressed
/**
* @return array action filters
*/
public function filters()
{
return array(
array(
'application.filters.html.ECompressHtmlFilter',
),
);
}
gzip turn on in apache
gzip_deflate almost alwayst turn on in apache - and it gziped all files automatically
RE: gzip turn on in apache
@Porcelanosa not if you're on a shared webhosting
For all controlleres & actions?
Can this be used in base
Controller
(descent ofCController
) class, placed inprotected/components
, with'actions' => '*'
and thus enable GZIP compression of any output application will generate (any controller and any action)? Or does it have to be put in every controller separately?Line breaks removed but spaces remained
I enabled
'doStripNewlines' => true,
then line breaks removed but spaces remained.
So I changed 80th line in ECompressHtmlFilter to first compress and then remove line breks. Now it works fine. I don't no why that thing happend.
$content = $this->compressHtml($content); if ($this->doStripNewlines){ $content = str_replace(array("\n", "\r"), '', $content); } echo $content;
Low compression level
Apparently the extension compresses well in most cases, but there are some places of my website that this extension causes html errors and the site doesn't display correctly
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.