Fixing Autoptimize problem with AdSense and other ad code

You know how important page speed is, and one of the key elements is minifying and optimizing your site’s source code. A WordPress plugin that does that automatically and very well is Autoptimize

The plugin minifies JavaScript, CSS, and HTML codes. It also combines JS and CSS files to make your code smaller. Also, only one resource needed to be loaded instead of multiple files.

Since many ad networks built their ad codes with 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 where they should show up.

Do you have to miss out on the great features that Autoptimize comes with when running ads?

The answer is, of course, no. Because Autoptimize also offers a way 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?

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

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

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

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 instead break than fix something. If your issue still gets resolved, adding scripts here, then please let us know.

Subscribe to our newsletter and get 2 add-ons for free!

* indicates required

General advice: Checking load order

The most important you need to understand when using the many options from Autoptimize is dependencies. This means that some parts of our and the ad’s code depend on other code, and if this does not load in time, nothing will work. 

In general, jQuery.js should be the first thing to load. Then the files of Advanced Ads Pro need to be added. Only after that can ads show up.

This means that, in general, moving every JavaScript code into the footer might work, but in this case, ensure not to exclude ads.

We discussed this issue with the author of Autoptimize in their support forum here, which is an excellent resource for learning more about Autoptimize.

Make it better

Increase your ad management skills without spending more time.
Join over 150,000 publishers and AdOpts increasing their ad revenue.