Fixing Autoptimize problem with AdSense and other ad codes
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 minifies JavaScript, CSS, and HTML codes. It also combines JS and CSS files to make your code smaller. Also, there is 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 from AdSense or any other ad code based on JavaScript from being “optimized”, you need to switch on Advanced Ads Pro.
The add-on automatically detects if Autoptimize is installed and makes each ad 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 Ad Manager tags. For the latter, don’t also forget to 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 instead 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 is 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 files of Advanced Ads Pro 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 an excellent resource to learn a bit more about Autoptimize.
Starting in 2009, Thomas’ own word game website grew to 40 MM page impressions per month. He then built Advanced Ads to help his colleagues to place ads and test different ad positions and networks tests without any coding skills. Thomas now enjoys improving the product for our more than 150,000 users worldwide.