Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

laravel 10.x support and new line bug fix's #177

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

},
"require-dev": {
"phpunit/phpunit": "^8.5 || ^9.0",
Expand Down
5 changes: 3 additions & 2 deletions src/Middleware/CollapseWhitespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public function apply($buffer)
"/\r/" => '',
"/\n/" => '',
"/\t/" => '',
"/ +/" => ' ',
"/> +</" => '><',
'/ >/' => '>',
'/ +/' => ' ',
'/> +</' => '><',
];

return $this->replace($replace, $this->removeComments($buffer));
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/InlineCss.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function injectStyle()
$injectStyle = implode(' ', $this->inline);

$replace = [
'#</head>(.*?)#' => "\n<style>{$injectStyle}</style>\n</head>"
'#</head>(.*?)#' => "<style>{$injectStyle}</style></head>"
];

$this->html = $this->replace($replace, $this->html);
Expand Down
11 changes: 7 additions & 4 deletions src/Middleware/InsertDNSPrefetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ public function apply($buffer)
);

$dnsPrefetch = collect($matches[0])->map(function ($item) {

$domain = (new TrimUrls)->apply($item[0]);
$domain = explode(
'/',
str_replace('//', '', $domain)
);

return "<link rel=\"dns-prefetch\" href=\"//{$domain[0]}\">";
})->unique()->implode("\n");
if (str_contains(@$domain[0], 'www.schema.org')) {
$domain[0] = 'www.schema.org';
}

return "<link rel=\"preconnect\" href=\"//{$domain[0]}\" crossorigin><link rel=\"dns-prefetch\" href=\"//{$domain[0]}\">";
})->unique()->implode('');

$replace = [
'#<head>(.*?)#' => "<head>\n{$dnsPrefetch}"
'#<head>(.*?)#' => "<head>{$dnsPrefetch}",
];

return $this->replace($replace, $buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/RemoveComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class RemoveComments extends PageSpeed
{
const REGEX_MATCH_JS_AND_CSS_COMMENTS = '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:|\\\|\'|\")\/\/.*))/';
const REGEX_MATCH_JS_AND_CSS_COMMENTS = '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:|\\\|\'|\"|[integrity])\/\/.*))/';
const REGEX_MATCH_HTML_COMMENTS = '/<!--[^]><!\[](.*?)[^\]]-->/s';

public function apply($buffer)
Expand Down