for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Abordage\LaravelHtmlMin\Middleware;
use Abordage\LaravelHtmlMin\Facades\HtmlMin;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class HtmlMinify
{
/**
* @param Request $request
* @param Closure $next
* @return Response|mixed
*/
public function handle(Request $request, Closure $next)
$response = $next($request);
if (!config('html-min.enable')) {
return $response;
}
if (!in_array(strtoupper($request->getMethod()), ['GET', 'HEAD'])) {
if (!$response instanceof Response) {
if (!$response->getStatusCode() != 200) {
$html = $response->getContent();
if (class_exists('\BeyondCode\ServerTiming\Facades\ServerTiming')) {
\BeyondCode\ServerTiming\Facades\ServerTiming::start('Minification');
/** @phpstan-ignore-next-line */
$htmlMin = HtmlMin::minify($html);
\BeyondCode\ServerTiming\Facades\ServerTiming::stop('Minification');
return $response->setContent($htmlMin);