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:

https://cdnjs.cloudflare.com/ajax/libs/Flowtype.js/1.1.0/flowtype.min.js

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

cdnjs.cloudflare.com

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

Helper plugin

📥  Download (.zip): WP Rocket | External Script Handler

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

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:

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?