codeigniter ajax中的gzip压缩不起作用
gzip compression in codeigniter ajax not works
顺便说一句,我使用的是codeigniter 3.0.1,我启用了钩子,它工作得很好,但它停止了所有ajax调用方法。下面是我用来启用gzip压缩的代码:
$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();
}
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();
}
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Ember Data DS.Model's set函数不起作用
- JsFiddle上的鼠标事件不起作用
- 我的AngularJS表达式没有'不起作用
- 点击按钮输入不起作用
- 面向对象的Javascript代码在IE7中不起作用
- 分部隐藏在jquery中不起作用
- 在phonegap应用程序内部重定向不起作用
- Array.length似乎不起作用;console.log则显示其他情况
- $ionicplatform内的$scope不;不起作用
- 我的javascript for循环不起作用
- Meteor-添加用户自定义字段的方法不起作用
- 为什么 .focus() 不起作用,而 .css(“color”,“red”) 在同一个选择器上起作用
- grunt上的压缩文件夹不起作用
- codeigniter ajax中的gzip压缩不起作用
- 为什么GZip压缩不起作用