diff --git a/composer.json b/composer.json index 7e17db7..c27dfe1 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^8.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0|^10.0" + "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0" }, "require-dev": { "phpunit/phpunit": "^8.5 || ^9.0", diff --git a/config/laravel-page-speed.php b/config/laravel-page-speed.php index 66a0739..a00e1e9 100644 --- a/config/laravel-page-speed.php +++ b/config/laravel-page-speed.php @@ -56,4 +56,17 @@ '*.m4v', '*.torrent' ], + + /* + |-------------------------------------------------------------------------- + | Skip Custom Domain + |-------------------------------------------------------------------------- + | + | Skip Custom Domain to exclude. + | + */ + + 'domain' => [ + // for eg: str_replace(['https://', 'http://'], ['', ''], env('FILAMENT_DOMAIN')) + ], ]; diff --git a/src/Middleware/CollapseWhitespace.php b/src/Middleware/CollapseWhitespace.php index c7e3f4d..37103a7 100644 --- a/src/Middleware/CollapseWhitespace.php +++ b/src/Middleware/CollapseWhitespace.php @@ -2,17 +2,28 @@ namespace RenatoMarinho\LaravelPageSpeed\Middleware; +use Exception; + class CollapseWhitespace extends PageSpeed { public function apply($buffer) { + if (str_contains($buffer, 'Error:')) { + return $buffer; + } + + if (in_array(request()?->host(), config('laravel-page-speed.domain'), true)) { + return $this->replace([], $this->removeComments($buffer)); + } + $replace = [ "/\n([\S])/" => '$1', "/\r/" => '', "/\n/" => '', "/\t/" => '', - "/ +/" => ' ', - "/> + '><', + '/ >/' => '>', + '/ +/' => ' ', + '/> + '><', ]; return $this->replace($replace, $this->removeComments($buffer)); diff --git a/src/Middleware/InlineCss.php b/src/Middleware/InlineCss.php index 5041b0a..418c9fd 100644 --- a/src/Middleware/InlineCss.php +++ b/src/Middleware/InlineCss.php @@ -42,7 +42,7 @@ private function injectStyle() $injectStyle = implode(' ', $this->inline); $replace = [ - '#(.*?)#' => "\n\n" + '#(.*?)#' => "" ]; $this->html = $this->replace($replace, $this->html); diff --git a/src/Middleware/InsertDNSPrefetch.php b/src/Middleware/InsertDNSPrefetch.php index 8e40053..4204fc4 100644 --- a/src/Middleware/InsertDNSPrefetch.php +++ b/src/Middleware/InsertDNSPrefetch.php @@ -14,6 +14,9 @@ public function apply($buffer) ); $dnsPrefetch = collect($matches[0])->map(function ($item) { + if (str_contains($item[0], 'debugbar')) { + return; + } $domain = (new TrimUrls)->apply($item[0]); $domain = explode( @@ -21,11 +24,15 @@ public function apply($buffer) str_replace('//', '', $domain) ); - return ""; - })->unique()->implode("\n"); + if (str_contains(@$domain[0], 'www.schema.org')) { + $domain[0] = 'www.schema.org'; + } + + return ""; + })->unique()->implode(''); $replace = [ - '#(.*?)#' => "\n{$dnsPrefetch}" + '#(.*?)#' => "{$dnsPrefetch}", ]; return $this->replace($replace, $buffer); diff --git a/src/Middleware/RemoveComments.php b/src/Middleware/RemoveComments.php index f6e476c..9c5d609 100644 --- a/src/Middleware/RemoveComments.php +++ b/src/Middleware/RemoveComments.php @@ -4,7 +4,7 @@ class RemoveComments extends PageSpeed { - const REGEX_MATCH_JS_AND_CSS_COMMENTS = '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?/s'; public function apply($buffer)