Skip to content

Instantly share code, notes, and snippets.

@rotaercz
Forked from garagesocial/filters.php
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rotaercz/d8c1ea446e7b1609cec4 to your computer and use it in GitHub Desktop.
Save rotaercz/d8c1ea446e7b1609cec4 to your computer and use it in GitHub Desktop.
<?php
### --- Snip --- ###
App::after(function($request, $response)
{
// HTML Minification
if(App::Environment() != 'local')
{
if($response instanceof Illuminate\Http\Response)
{
$output = $response->getOriginalContent();
$filters = array(
'/<!--([\s\S]*?)-->/' => '', // Remove HTML Comments
'/(?<!\S)\/\/\s*[^\r\n]*/' => '', // Remove comments in the form /* */
'/\s{2,}/' => ' ', // Shorten multiple white spaces
'/(\r?\n)/' => '', // Collapse new lines
);
$output = preg_replace(array_keys($filters), array_values($filters), $output);
$response->setContent($output);
}
}
});
### --- Snip --- ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment