Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
markvaneijk committed May 10, 2024
2 parents cad4c50 + b2bc468 commit 22022e5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/Middleware/MinifyHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class MinifyHtml
{
public function handle($request, $next)
{
if(! $this->shouldMinifyHtml($request)) {
if (! $this->shouldMinifyHtml($request)) {
return $next($request);
}

$response = $next($request);

foreach(config('minify-html.transformers') as $x => $transformer) {
foreach (config('minify-html.transformers') as $x => $transformer) {
$response = (new $transformer)->transform($response);
}

Expand All @@ -23,23 +23,23 @@ public function handle($request, $next)

public function shouldMinifyHtml(Request $request)
{
if(! config('minify-html.enabled')) {
if (! config('minify-html.enabled')) {
return false;
}

if(! in_array($request->method(), ['GET', 'HEAD'])) {
if (! in_array($request->method(), ['GET', 'HEAD'])) {
return false;
}

if($request->isJson() || $request->isXml()) {
if ($request->isJson() || $request->isXml()) {
return false;
}

if(! str_contains($request->header('Accept'), 'html')) {
if (! str_contains($request->header('Accept'), 'html')) {
return false;
}

if($request->ajax()) {
if ($request->ajax()) {
return false;
}

Expand Down
1 change: 0 additions & 1 deletion src/MinifyHtmlServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Vormkracht10\MinifyHtml\Commands\MinifyHtmlCommand;

class MinifyHtmlServiceProvider extends PackageServiceProvider
{
Expand Down
4 changes: 2 additions & 2 deletions src/Transformers/RemoveWhitespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class RemoveWhitespace
public function hideElements(string $html): string
{
foreach ($this->ignoreElements as $element) {
$pattern = '~<' . $element . '[^>]*>(.*)</' . $element . '>~Uuis';
$pattern = '~<'.$element.'[^>]*>(.*)</'.$element.'>~Uuis';
if (preg_match_all($pattern, $html, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$this->hiddenElements['#' . md5($match[1]) . '#'] = $match[1];
$this->hiddenElements['#'.md5($match[1]).'#'] = $match[1];
}
}
}
Expand Down

0 comments on commit 22022e5

Please sign in to comment.