Skip to content

Instantly share code, notes, and snippets.

@rgomezcasas
Forked from garagesocial/filters.php
Last active December 24, 2015 10:49
Show Gist options
  • Save rgomezcasas/6786469 to your computer and use it in GitHub Desktop.
Save rgomezcasas/6786469 to your computer and use it in GitHub Desktop.
Minificar salida del HTML en Laravel 4
<?php
App::after(function($request, $response)
{
// Elimina esta condición si quieres probarlo en local
if (App::Environment() == 'production')
{
if ($response instanceof Illuminate\Http\Response)
{
$output = $response->getOriginalContent();
$filters = array(
'/<!--([^\[|(<!)].*)/' => '', // Eliminamos los comentarios HTML
'/<(?<!\S)\/\/\s*[^\r\n]*/' => '', // Borra los comentarios /* */
'/<\s{2,}/' => '', // Combina los espacios
'/<(\r?\n)/' => '', // Elimina los saltos de linea
);
$output = preg_replace(array_keys($filters), array_values($filters), $output);
$response->setContent($output);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment