Skip to content

Instantly share code, notes, and snippets.

@leemason
Forked from zmsaunders/filters.php
Created May 31, 2014 09:49
Show Gist options
  • Select an option

  • Save leemason/09f05971c0b31dd8d2bf to your computer and use it in GitHub Desktop.

Select an option

Save leemason/09f05971c0b31dd8d2bf 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();
// Clean comments
$output = preg_replace('/<!--([^\[|(<!)].*)/', '', $output);
$output = preg_replace('/(?<!\S)\/\/\s*[^\r\n]*/', '', $output);
// Clean Whitespace
$output = preg_replace('/\s{2,}/', '', $output);
$output = preg_replace('/(\r?\n)/', '', $output);
$response->setContent($output);
}
}
});
### --- Snip --- ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment