alaca / WP-Performance

Speed optimization plugin for Wordpress
https://wordpress.org/plugins/wp-performance/
22 stars 4 forks source link

Url.getClean function could use parse_url, as internal files are marked external #15

Closed mpeg closed 4 years ago

mpeg commented 4 years ago

Hey, let me preface this by saying I'm not a PHP developer so it's entirely possible I don't understand the issue in a deep way, on my installs of this plugin I've replaced the getClean function in Url class with:

public static function getClean( $path )
{
    return parse_url($path)['path'];
}

as otherwise, I get issues with some plugins having their files identified as external, and seems to work just fine for removing querystring and whatnot from the file path

I'm happy to continue using my modified plugin version, but it would be great if we could reach some sort of fix for the external files issue

alaca commented 4 years ago

Hi, would you mind sharing which plugins are getting files identified as external? Your modification might work in some cases, but in general, this is not what getClean function should return. getClean function should return the file path relative to Wordpress ABSPATH If the file is "local" file. For example, let's say we have a WP installation in a subdirectory called wp and we are using a theme called example-theme. If we try to get the path of the style.css file with the modified function, the file name will be /wp/wp-content/themes/example-theme/style.css, with current function the file name will be /wp-content/themes/example-theme/style.css. Another example is the file path of external files like google fonts. For example https://fonts.googleapis.com/css?family=Somefont. your method will return the path of this file which in this case is /css which might return true if the folder css actually exist in the site root. Hope this helps.

mpeg commented 4 years ago

I see, that makes sense.

The plugin that's incompatible is Essential Addons for Elementor, which uses urls without schema for both scripts and stylesheets (like "//yoursite.com/wp-dir/style.css") so the browser can choose http/https

This is not parsed correctly by the plugin and shown as an external file.

alaca commented 4 years ago

This issue will be sorted out in the next update. Thanks.