You know how important page speed is and one of the key elements to it is minifying and optimizing your site’s source code. A WordPress plugin that does that automatically and very well is Autoptimize. The plugin basically minifies JavaScript, CSS and HTML codes and also combines JS and CSS files. This not only makes the code smaller, but also only needs one resource to be loaded instead of multiple files.

Since codes from many ad networks are build on JavaScript they get moved into the combined file too. The problem is that ad codes don’t work when put into an additional file. In most cases the ad codes need to be put directly into the content at the place where they should show up.

So, do you have to miss out the great features that Autoptimize comes with when running ads?

The answer is of course no, because Autoptimize also offers a ways to make exceptions from this behavior for particular pieces of code. Advanced Ads Pro now uses this feature automatically for every ad code.

How can you exclude ads from Autoptimize?

In order to exclude ads like from AdSense or any other ad code based on JavaScript from being “optimized”, you just need to switch on Advanced Ads Pro.

The add-on automatically detects if Autoptimize is installed and makes each ad that is managed with Advanced Ads an exception from Autoptimize code optimization.

So far, this feature helped users with AdSense, different ad networks, custom JavaScript code and even Google DFP tags. For the latter, don’t forget to also manage the header tags with Advanced Ads.

In case that you might not want to exclude your ads from Autopimize – e.g. if you only have ads with static html – then you can also disable this feature in the Pro-settings.

Don’t exclude AA scripts from Autoptimize

There is a setting in Autoptimize that allows you to exclude specific scripts from optimization. Adding Advanced Ads’ script there might actually rather break than fix something. If your issue still gets resolved adding scripts here then please let us know.

General advice: Checking load order

When using the many options from Autoptimize, the most important you need to understand are dependencies. This means that some parts of our and the ad’s code depend on other code and if this is not loaded in time, nothing will work. In general, jQuery.js should be the first thing to load. Then the Advanced Ads Pro files need to be added. Only after that, ads can show up.

This means that in general, also moving every JavaScript code into the footer might work, but in this case, make sure that no ads are excluded.

We discussed such an issue with the author of Autoptimize in their support forum here, which is a good resource to learn a bit more about Autoptimize as well.