-
-
Save miguelbalboa/9224ecc1daeadff5ab49 to your computer and use it in GitHub Desktop.
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
<?php | |
### --- Snip --- ### | |
App::after(function($request, $response) | |
{ | |
// HTML Minification | |
if(App::Environment() != 'local') | |
{ | |
if($response instanceof Illuminate\Http\Response && str_contains($response->headers->get('content-type'), 'text/html')) | |
{ | |
$output = $response->getOriginalContent(); | |
$filters = array( | |
'/<!--([^\[|(<!)].*)/' => '', // Remove HTML Comments (breaks with HTML5 Boilerplate) | |
'/(?<!\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
Hello @EmilMoe, This is for Laravel, and you put is code in global.php file,
You can see original gist in https://gist.github.com/zmsaunders/5619519.
¡Saludos!