Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
h-mj
committed
Apr 23, 2017
1 parent
69acbfe
commit f59f1aa
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// https://github.com/bcit-ci/CodeIgniter/wiki/Compress-HTML-output | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
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 [\t\r\n\f\v] 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. | ||
< # Either a blacklist start tag. | ||
(?>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(); | ||
} | ||
|
||
/* End of file compress.php */ | ||
/* Location: ./system/application/hooks/compress.php */ |