Skip to content

Instantly share code, notes, and snippets.

@samthomson
Created November 5, 2014 09:48
Show Gist options
  • Save samthomson/7e9f1ddee457e34b100f to your computer and use it in GitHub Desktop.
Save samthomson/7e9f1ddee457e34b100f to your computer and use it in GitHub Desktop.
laravel - filter to minify output
App::after(function($request, $response)
{
// HTML Minification
if(!Config::get('app.debug'))
{
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);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment