Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 6572963

Browse files
committed
[CHG] Method compress to minify Html code
1 parent f7270b2 commit 6572963

3 files changed

Lines changed: 38 additions & 32 deletions

File tree

application/config/hooks.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
|
1313
*/
1414

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'
15+
/*
16+
| -------------------------------------------------------------------------
17+
| Compress output
18+
| -------------------------------------------------------------------------
19+
|
20+
*/
21+
$hook['display_override'][] = array(
22+
'class' => '',
23+
'function' => 'minify_html',
24+
'filename' => 'minify_html.php',
25+
'filepath' => 'hooks'
2126
);

application/hooks/compress.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

application/hooks/minify_html.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
defined('BASEPATH') OR exit('No direct script access allowed');
3+
4+
5+
if ( ! function_exists('minify_html'))
6+
{
7+
function minify_html()
8+
{
9+
ini_set('pcre.recursion_limit', '16777');
10+
11+
$CI =& get_instance();
12+
13+
$buffer = $CI->output->get_output();
14+
15+
$re = '%(?>[^\S ]\s*| \s{2,})(?=[^<]*+(?:<(?!/?(?:textarea|pre|script)\b)[^<]*+)*+(?:<(?>textarea|pre|script)\b| \z))%Six';
16+
17+
$new_buffer = preg_replace($re, '', $buffer);
18+
19+
if ($new_buffer === NULL)
20+
{
21+
$new_buffer = $buffer;
22+
}
23+
24+
$CI->output->set_output($new_buffer);
25+
$CI->output->_display();
26+
}
27+
}

0 commit comments

Comments
 (0)