Before submitting an issue please check that you’ve completed the following steps:
Describe the bug
The following was found on a multisite where the subsites were in subfolders. I haven't checked it, but the same should stand for WordPress subfolder installations.
On Kinsta, who do their own CDN rewriting, CSS/JavaScript combination fails when the site's URL contains a path, e.g. https://www.example.com/path/.
The following check is failing:
https://github.com/wp-media/wp-rocket/blob/8f7f67b621e5085ccf6424a08a15ce636e4fbf2f/inc/functions/formatting.php#L512
This is because in the following line:
https://github.com/wp-media/wp-rocket/blob/8f7f67b621e5085ccf6424a08a15ce636e4fbf2f/inc/Engine/CDN/Subscriber.php#L238
we are using only the host:
$site_url = $site_url_parts['scheme'] . '://' . $site_url_parts['host'];
Eventually the $file doesn't contain the root directory path here:
https://github.com/wp-media/wp-rocket/blob/8f7f67b621e5085ccf6424a08a15ce636e4fbf2f/inc/functions/formatting.php#L497
This returns false and assets aren't minified/combined.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
CSS/JavaScript combination should work regardless of the site's URL containing a path when using Kinsta or any host that does CDN rewriting.
Additional context
Related ticket: https://secure.helpscout.net/conversation/1272259848/191944?folderId=2135277
Backlog Grooming (for WP Media dev team use only)
Any updates on this? It's quite a bad bug :/
The customer opened a new ticket about this case:
https://secure.helpscout.net/conversation/1332879329/210266?folderId=2683093
props to @alfonso100
we can solve this issue by replacing the following line
with the following line
$site_url = untrailingslashit( $site_url_parts['scheme'] . '://' . $site_url_parts['host'] . $site_url_parts['path'] );
it should do the trick, I tried that on one of our customer's sites and it seems working.
additional context till finishing grooming:
Kinsta ( and I think BunnyCDN ) when using CDN it removes the subdirectory path from the assets urls so when replacing the site url with the content path it gives not correct path so what we did here is to add the path also to the site url
for example:
main url: https://example.org/sub/
asset url without cdn: https://example.org/sub/wp-content/themes/test/style.css
asset url: https://mk0runnerslab22n01ig.kinstacdn.com/wp-content/themes/test/style.css
so we try to replace https://mk0runnerslab22n01ig.kinstacdn.com/ with https://example.org/ assuming that the asset url has the subdirectory on it (but at kinsta it isn't) so the final url is: https://example.org/wp-content/themes/test/style.css and this is not correct.
Related ticket: https://secure.helpscout.net/conversation/1367510564/223237/
@engahmeds3ed have already confirmed the fix there.
Most helpful comment
props to @alfonso100
we can solve this issue by replacing the following line
https://github.com/wp-media/wp-rocket/blob/28e7b00cb74df0a18b79c65631d0ba438e019db8/inc/Engine/CDN/Subscriber.php#L231
with the following line
it should do the trick, I tried that on one of our customer's sites and it seems working.