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.

Remember: Manual code edits are required before use!

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?