Javascript codeigniter ajax中的gzip压缩不起作用
顺便说一句,我使用的是codeigniter 3.0.1,我启用了钩子,它工作正常,但它停止了所有ajax调用方法。下面是我用来启用gzip压缩的代码:Javascript codeigniter ajax中的gzip压缩不起作用,javascript,php,ajax,codeigniter,Javascript,Php,Ajax,Codeigniter,顺便说一句,我使用的是codeigniter 3.0.1,我启用了钩子,它工作正常,但它停止了所有ajax调用方法。下面是我用来启用gzip压缩的代码: $config['enable_hooks']=TRUE system/application/config/hooks.php // compress output $hook['display_override'][] = array( 'class' => '', 'function' => 'compres
$config['enable_hooks']=TRUE代码>
system/application/config/hooks.php
// compress output
$hook['display_override'][] = array(
'class' => '',
'function' => 'compress',
'filename' => 'compress.php',
'filepath' => 'hooks'
);
system/application/hooks/compress.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function compress()
{
$CI =& get_instance();
$buffer = $CI->output->get_output();
$search = array(
'/\n/', // replace end of line by a space
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
' ',
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $buffer);
$CI->output->set_output($buffer);
$CI->output->_display();
}
system/application/config/hooks.php
//压缩输出
$hook['display\u override'][]=数组(
“类”=>“”,
'函数'=>'压缩',
'filename'=>'compress.php',
“文件路径”=>“挂钩”
);
system/application/hooks/compress.php
函数压缩()
{
ini_集(“pcre.递归极限”,“16777”);
$CI=&get_instance();
$buffer=$CI->output->get_output();
$re='%#将空格折叠到除黑名单元素外的所有位置。
(?>#匹配除单个空格外的所有空格。
[S]S*#一个[trnfv]和零个或多个ws,
|s{2,}#或两个或多个连续的任意空格。
)#注意:剩余的正则表达式完全不使用文本。。。
(?=#确保我们没有被列入黑名单。
[^函数压缩()
{
ini_集(“pcre.递归极限”,“16777”);
$CI=&get_instance();
$buffer=$CI->output->get_output();
$re='%#将空格折叠到除黑名单元素外的所有位置。
(?>#匹配除单个空格外的所有空格。
[S]S*#一个[trnfv]和零个或多个ws,
|s{2,}#或两个或多个连续的任意空格。
)#注意:剩余的正则表达式完全不使用文本。。。
(?=#确保我们没有被列入黑名单。
[^浏览器中的ajax响应是什么。浏览器中的ajax响应是什么。
function compress()
{
ini_set("pcre.recursion_limit", "16777");
$CI =& get_instance();
$buffer = $CI->output->get_output();
$re = '%# Collapse whitespace everywhere but in blacklisted elements.
(?> # Match all whitespans other than single space.
[^S ]s* # Either one [trnfv] and zero or more ws,
| s{2,} # or two or more consecutive-any-whitespace.
) # Note: The remaining regex consumes no text at all...
(?= # Ensure we are not in a blacklist tag.
[^<]*+ # Either zero or more non-"<" {normal*}
(?: # Begin {(special normal*)*} construct
< # or a < starting a non-blacklist tag.
(?!/?(?:textarea|pre|script)b)
[^<]*+ # more non-"<" {normal*}
)*+ # Finish "unrolling-the-loop"
(?: # Begin alternation group.
textarea|pre|script)b
| z # or end of file.
) # End alternation group.
) # If we made it here, we are not in a blacklist tag.
%Six';
$new_buffer = preg_replace($re, " ", $buffer);
// We are going to check if processing has working
if ($new_buffer === null)
{
$new_buffer = $buffer;
}
$CI->output->set_output($new_buffer);
$CI->output->_display();
}