Skip to content

Commit 6dc81c5

Browse files
author
Emmanuel Campait
committed
Active GZIP and compress via Hooks
1 parent 01ebef3 commit 6dc81c5

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

application/config/config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
| setting this variable to TRUE (boolean). See the user guide for details.
9595
|
9696
*/
97-
$config['enable_hooks'] = FALSE;
97+
$config['enable_hooks'] = TRUE;
9898

9999
/*
100100
|--------------------------------------------------------------------------
@@ -456,7 +456,7 @@
456456
| by the output class. Do not 'echo' any values with compression enabled.
457457
|
458458
*/
459-
$config['compress_output'] = FALSE;
459+
$config['compress_output'] = TRUE;
460460

461461
/*
462462
|--------------------------------------------------------------------------

application/config/hooks.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@
1111
| http://codeigniter.com/user_guide/general/hooks.html
1212
|
1313
*/
14+
15+
/* http://php.quicoto.com/how-to-speed-up-codeigniter/ */
16+
$hook['display_override'] = array(
17+
'class' => '',
18+
'function' => 'compress',
19+
'filename' => 'compress.php',
20+
'filepath' => 'hooks'
21+
);

application/hooks/compress.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
defined('BASEPATH') OR exit('No direct script access allowed');
3+
4+
$CI =& get_instance();
5+
$buffer = $CI->output->get_output();
6+
7+
$search = array(
8+
'/\>[^\S ]+/s',
9+
'/[^\S ]+\</s',
10+
'/(\s)+/s',
11+
'#(?://)?<!\[CDATA\[(.*?)(?://)?\]\]>#s',
12+
'/\>(\s)+\</'
13+
);
14+
15+
$replace = array(
16+
'>',
17+
'<',
18+
'\\1',
19+
"//&lt;![CDATA[\n".'\1'."\n//]]>",
20+
'><'
21+
);
22+
23+
$buffer = preg_replace($search, $replace, $buffer);
24+
25+
$CI->output->set_output($buffer);
26+
$CI->output->_display();

0 commit comments

Comments
 (0)