|
|
|
| Здравствуйте, уважаемые пользователи форума! Хочу сделать компрессию выводимого кода HTML в smarty. Написал такую функцию:
function smartyoutputcompress( $tpl_output, &$smarty ) {
if( headers_sent() )
return $tpl_output;
if( ($t = ob_get_contents()) != '' ) {
$tpl_output = $t.$tpl_output;
ob_clean();
}
header( 'Content-Encoding: deflate' );
return gzcompress( $tpl_output, 4 );
}
Smarty()->registerFilter( 'output', 'smartyoutputcompress' );
|
Но к сожалению в IE сайт открываться не хочет. Помогите сделать что бы работало во всех браузерах. Просто моя страничка (исходный код) весит аж 270 килобайт. | |
|
|
|
|
|
|
|
для: pavluxa09
(08.07.2012 в 18:51)
| |
public function compression ($output) {
if (isset ($_SERVER['HTTP_ACCEPT_ENCODING'])) {
$HTTP_ACCEPT_ENCODING = $_SERVER['HTTP_ACCEPT_ENCODING'];
}
if (isset ($HTTP_ACCEPT_ENCODING)) {
if (strpos ($HTTP_ACCEPT_ENCODING, 'gzip') !== False) {
header ('Content-Encoding: gzip');
$compressed_data = gzencode ($output, GZIP_LEVEL);
$compression_method = 'gzip';
} elseif (strpos ($HTTP_ACCEPT_ENCODING, 'deflate') !== False) {
header ('Content-Encoding: deflate');
$compressed_data = gzdeflate ($output, GZIP_LEVEL);
$compression_method = 'deflate';
} elseif (empty ($HTTP_ACCEPT_ENCODING)) {
$compressed_data = $output;
$compression_method = 'no_compression';
} elseif (!empty ($HTTP_ACCEPT_ENCODING)) {
header ('HTTP/1.1 406 Not Acceptable core.compression');
$compressed_data = $output;
$compression_method = 'not_allowed';
}
} else {
$compressed_data = $output;
$compression_method = 'not_allowed';
}
$GLOBALS['compressed_size'] = strlen ($compressed_data);
$GLOBALS['uncompressed_size'] = strlen ($output);
$GLOBALS['compression_method'] = $compression_method;
header ('Content-Length: ' . $GLOBALS['compressed_size']);
return $compressed_data;
}
|
| |
|
|
|
|
|
|
|
для: serenya1983
(09.07.2012 в 11:44)
| | Веб-страница по адресу http:// возможно, временно недоступна или постоянно перемещена по новому адресу.
Ошибка 330 (net::ERR_CONTENT_DECODING_FAILED): Неизвестная ошибка. | |
|
|
|
|
|
|
|
для: pavluxa09
(09.07.2012 в 12:59)
| | UP | |
|
|
|