Excluding External JS from Concatenation

Sometimes there can be an issue with external JavaScript files and minification. External files cannot be minified, but they do get moved to the top of the page. To stop this from happening you can use the helper plugin below, but you will have to edit its code.

For example, if you would notice an issue with a file like this:


…the part of the URL that you would need to exclude from WP Rocket’s file optimization would look like this:


Similarly you would trim any other external file URL to its (sub-)domain part only.

Helper plugin

Heads up! You may have to edit the helper plugin before use!
Make sure the URL part you want to exclude is already listed in the code. If it’s not, add it as follows:

📥  Download (.zip): WP Rocket | External JS Hosts

Developers: You can find the code for this plugin on GitHub.

In order to add a custom script entry to the plugin, you would insert a line similar to the following one just before the return $external_js_hosts; statement:

$external_js_hosts[] = 'example.com';

Also, take note of the hosts that are already included in the plugin. Maybe you don’t even have to add yours again, because it is already there?