diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 270bedd..545a892 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ ubuntu-latest ] - php: [ 8.0, 7.4 ] + php: [ 8.0, 8.1 ] dependency-version: [ prefer-stable ] name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index a35bf44..17d7791 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "php": "^8.0", "statamic/cms": "^3.3", - "voku/html-min": "^4.4" + "voku/html-min": "^4.5" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.8", diff --git a/config/html-minify.php b/config/html-minify.php index af42c8d..2b91f46 100644 --- a/config/html-minify.php +++ b/config/html-minify.php @@ -18,4 +18,8 @@ 'removeSpacesBetweenTags' => false, 'removeOmittedQuotes' => false, 'removeOmittedHtmlTags' => false, + + 'excludedContentTypes' => [ + 'application/xml', + ], ]; diff --git a/src/HtmlMinifyMiddleware.php b/src/HtmlMinifyMiddleware.php index b33e17b..d87c5ca 100644 --- a/src/HtmlMinifyMiddleware.php +++ b/src/HtmlMinifyMiddleware.php @@ -4,6 +4,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Statamic\Support\Arr; use Symfony\Component\HttpFoundation\StreamedResponse; class HtmlMinifyMiddleware @@ -18,14 +19,21 @@ class HtmlMinifyMiddleware */ public function handle(Request $request, \Closure $next) { + /** @var $response \Illuminate\Http\Response */ $response = $next($request); if ($response instanceof StreamedResponse || $response instanceof JsonResponse) { return $next($request); } - $html = (new HtmlMinify($response->getContent()))->minifiedHtml(); + foreach (config('html-minify.excludedContentTypes') as $type) { + if ($response->headers->contains('content-type', $type)) { + return $next($request); + } + } + + $html = (new HtmlMinify($response->getContent()))->minifiedHtml(); return $response->setContent($html); } }