Cache Busting

Caching can improve page speed by serving a static version of a website. But when it comes to ads, there are a few things to keep in mind when using caching because websites often deliver ads dynamically.

With Cache Busting, Advanced Ads Pro offers an elegant solution to this problem. This feature becomes necessary on cached websites when you serve ads with features like:

By default, you only need to enable the module. Cache Busting will automatically choose the best method.

Requirements for Cache Busting

The Cache Busting works with caching provided by

  • plugins like WP Rocket, WP Super Cache, or W3 Total Cache
  • hosting providers
  • services like Cloudflare.

You can enable the specific Cache Busting behavior for each placement individually.

Steps to enable Cache Busting

  • Install and enable Advanced Ads Pro
  • Enable the Cache Busting module in Advanced Ads > Settings > Pro.
  • Leave the appearing options at default
  • Refresh your website’s cache
  • By default, Cache busting is only applied to placements
  • Your website’s frontend does not have any critical JavaScript errors

Cache Busting methods

Advanced Ads comes with three technically different methods for Cache Busting.

  1. off
  2. passive
  3. AJAX

By default, the Cache Busting option for placements is set to “auto”. This setting tells Advanced Ads to choose the method with the minor impact on performance.

Cache-busting option on the placement edit page.
Find-tune Cache Busting options for each placement.

Only choose another method than the default settings if you know its implications.


Advanced Ads automatically switches off Cache Busting if it is not needed. As a rule of thumb: You don’t need Cache Busting if you show the same ad all the time to all of your users in a given position. E.g., as soon as you show different ads to users with other devices, locations, or privacy settings, you need to enable Cache Busting.

You don’t need to enable the Cache Busting module if your site is not cached, or you are sure not to show different ads to different users.

See also “When you can disable Cache Busting” below.


Passive Cache Busting loads all possible ads into the page’s HTML code and uses JavaScript to deliver the correct ad. This method is super fast but takes more space in your HTML code and doesn’t work for all conditions.

This method is automatically selected when you show dynamic ads, and AJAX Cache Busting is not needed. It mainly handles these cases:


AJAX Cache Busting uses an AJAX call (admin-ajax.php) to load the correct ad. This method needs more performance but works with all dynamic features also mentioned under “passive”.

You need to choose this method for ads that use:

  • PHP or WordPress shortcodes, though you can disable AJAX Cache Busting if the content created by PHP or shortcodes is static
  • one of the following visitor conditions: Geo-location, User Capability, User Role, Logged-In
  • the “Ad Group” ad type

When you can disable Cache Busting

Cache Busting either needs more performance (AJAX Cache Busting) or source code (passive Cache Busting). Therefore, you should consider not using it in some cases, e.g.

  • you have so many different pages that despite caching, the ads in a rotation are delivered equally
  • your PHP output is static, e.g., echo “hello”;
  • you only use visitor conditions for visitors that don’t use caching (e.g., admins)
  • you only use the Device condition and no other visitor condition, plus you cache your site using WP Rocket. You can enable a separate mobile cache in their settings and follow this article to apply their mobile cache also to tablets, since our Device condition uses wp_is_mobile.

Cache busting settings

You find the main settings for Cache Busting under Advanced Ads > Settings > Pro > Cache Busting.

Available options for the cache busting module.
Available options for the Cache Busting module.

Default Cache Busting methods

Choose the default methods based on the information under “Cache Busting methods” above.

The default options should cover the most common use cases.

You might want to disable “AJAX” as a fallback option when you experience performance issues due to many calls to admin-ajax.php.

Forcing passive Cache Busting

If you enable “Force passive Cache Busting”, then passive Cache Busting would be used also for

  • ads and groups placed without a placement
  • single ads in placements that would normally not use Cache Busting

You can disable the latter by setting the placement’s Cache Busting option to “off”.

If the ad or group needs AJAX Cache Busting, Advanced Ads would not use Cache Busting at all since you can only enable passive Cache Busting for manually placed ads and groups.

Visitor profile

Advanced Ads Cache Busting falls back to an AJAX request for some visitor conditions. Since AJAX requests need additional performance on the server and show up with a delay, we try to reduce them as much as possible. This is why we store the information retrieved through AJAX in the user’s browser.

Visitor conditions that make use of this feature are:

Advanced Ads stores visitor information in a cookie. When the cookie exists and is valid, Cache Busting doesn’t need an AJAX request for those visitor conditions where it usually does, e.g., geo-targeting.

Advanced Ads determines automatically when a cookie refresh is needed, e.g., when an ad uses a condition that wasn’t used before by any ad. You can also use the Update user profile button on Advanced Ads > Settings > Pro to force an update. You might need this when you change a lot of user information, like their roles or capabilities.

The default cookie expiry is set to 30 days. You can change this period by adding the ADVANCED_ADS_PRO_USER_COOKIE_MAX_AGE constant with the duration in seconds to your wp-config.php file.

define( 'ADVANCED_ADS_PRO_USER_COOKIE_MAX_AGE', 604800 ); // cookie expiry in 7 days

You can set this constant to 0 to disable the cookie.

By adding #debug=true to the URL, you can see a readable output of the cookie in the browser console.

There is still an AJAX request when using our Tracking with an appropriate method enabled.


Caching and Cache Busting are very advanced features. Some plugins and servers may use too restrictive settings.

Please let us know if you meet issues we are not covering here.

Compatibility warning (passive Cache Busting)

The following warning in the ad parameter options of an ad might indicate a compatibility problem between the ad content and passive Cache Busting.

The code of this ad might not work properly with activated Cache Busting.

This might be a false positive, and your ad works without problems. But if you use passive Cache Busting for this ad, you should check in the frontend to be sure.

A few reasons for this warning:

  • use of <?php … ?> without the PHP option enabled
  • use of invalid PHP code
  • use of unknown HTML elements. This causes most of the known false positives, though
  • use of jQuery(document).ready()
  • use of any other JavaScript variable or object defined outside of the current ad

Header-Codes (AJAX Cache Busting)

Some ad networks require you to add some extra code to your theme’s <head> section. Delivering these kinds of tags with Cache Busting might result in problems with your ad networks. We also lack a use case where such dynamic header codes are needed, so please let us know if you have one.

You must not include ads between wp_head() and the </head> tag.

Caching and Cookies

Advanced Ads Pro might use cookies to send dynamic information to ads. Very restrictive caches might either remove those cookies to allow cache or set cookies that break the caching at all. Please, ask the developer of your caching plugin or your hoster if you are unsure about this.

Cache Busting in Widgets

You have two options when it comes to using Cache Busting in widgets

  • Use the Sidebar Widget placement and assign it to the widget
  • Enable Advanced Ads > Settings > Pro > Cache Busting > Force passive Cache Busting

Either of them will enable Cache Busting for the ad(s) in the widget when needed.

No Cache Busting within feed or external sites

If you send out a feed or promote your content on external sites, Cache Busting is not working, and will fall back not to display the ad at all. If you want to display ads within your feed, create another ad with the appropriate display conditions.

Other questions about AJAX Cache Busting

How does Cache Busting affect performance?

AJAX Cache Busting certainly adds more weight to the server as the number of requests is increased.

To avoid issues with your provider and load times, you should:

  • use passive Cache Busting whenever possible
  • don’t use Cache Busting on static positions: does a placement only serve a single ad to all visitors? Do not cache-bust it!
  • try to combine ads and position using javascript: fewer requests mean faster page load
  • use persistent object cache plugins like W3 Total Cache or em-object-cache to avoid excessive database load
  • bypass proxies for AJAX calls (especially the /wp-admin/admin-ajax.php path)

Does Cache Busting work for all ads?

There are some issues with ad codes that try to include multiple external scripts at once (<script src="..">).

Please split those into multiple ads, or do not use Cache Busting on them.

You must not include ads between wp_head() and the </head> tag.

How are cache-busted ads loaded?

The ad content is retrieved from the backend and analyzed.

Does it contain any external JavaScript (<script src="..">)? Then it is loaded asynchronously due to browser limitations.

Otherwise, ads block page load until they are loaded.

How to force asynchronous loading with Cache Busting

Add the async parameter to the <script> tag like with <script async>.

My ads are loaded asynchronous (sometimes) but should be blocking!

Due to browser limitations, there is a forced switch to load any ad asynchronously while an external script is included.

You certainly have a <script src=".."> loaded before your ad.

If it is possible, add async (see above) to the troublesome ad, or do not use Cache Busting for it if possible.

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

* indicates required


While reading the Limitations & FAQ section might help to fix issues as well, here are a few quick ideas to check in case this feature doesn’t seem to work for you:

  • Cache Busting also changes some markup in the frontend, so be sure to clear your cache after changing Cache Busting options or setup.
  • Cache Busting only works when the ad or group you display uses a placement or if you enable the option to force it.
  • check for JavaScript errors in the browser’s developer console. Those could break Cache Busting too.

Ads are loading delayed

The ads that use Cache Busting to load can appear only after the rest of your site is loaded. This is needed since Cache Busting also reacts to the content on your page.

Speeding up your site’s load time in general as a possible solution to speed up the ads’ loading time as well as offloading file loading to a CDN.

Issues with the AJAX call

AJAX Cache Busting uses admin-ajax.php to request ads from the server. It uses the advads_ads_select action.

Advanced Ads only uses AJAX calls when needed (see above) and combines all AJAX-loaded ads into a single call. The plugin uses individual calls when an ad is delayed (e.g., using deferred triggers for PopUp ads) or automatic ad rotations.

If you experience issues with the AJAX call, disable AJAX Cache Busting as the default or fallback method under Advanced Ads > Settings > Pro > Cache Busting.

Ad setups with HEAD and BODY codes

Some ad networks require you to place two ad codes. One is in the head or footer of your site and one at the position in the website body where a specific ad should appear.

The body tags often stay empty when they are loaded with a delay after the head code.

Some solutions you could test:

  • for Google Ad Manager, use our Google Ad Manager plugin
  • combine head and body codes into one and place that combined code in the body
  • trigger the code that fills the body tags again using JavaScript with setTimeout()
  • disable Cache Busting for either of the placements or both of them

Looking for Cache Busting code

When Cache Busting is used for a placement, the ad’s code is not directly visible in the frontend. Instead, a placeholder is visible in the source code. This placeholder is only filled if the ad or placement conditions allow it.

The placeholder includes a random ID and class and a class based on the placement name. The prefix is derived from the ID Prefix option set under Advanced Ads > Settings > General. E.g.,

<div class="prefix-47fc157d9a98c6a5ef9fa250b5c5103b prefix-below-the-content" id="prefix-47fc157d9a98c6a5ef9fa250b5c5103b"></div>Code language: HTML, XML (xml)

The placeholder is easy to confuse with the placement container because the latter uses the same static class derived from the placement name and a shorter ID. E.g.,

<div class="prefix-below-the-content" id="prefix-1977363758">...</div>Code language: HTML, XML (xml)

Debug mode

Cache Busting has its own debug mode, which you can enable by adding #debug=true to the current URL (and reloading the page). The output is displayed in the JavaScript error console. This might be too technical for you if you don’t know what this means. We are considering adding a more straightforward debug mode in the future.

The debug output contains information about Cache Busting (AJAX and passive), site setup, and loaded ads. That helps us to understand your setup without a login. No data is visible that other parties couldn’t also see without debug mode.

JS file Minification

When JavaScript files are minified by a script, plugin, or hosting service, it might also break how Cache Busting works. As a last measure, exclude the following files from minification:

  • /wp-content/plugins/advanced-ads-pro/assets/js/postscribe.js
  • /wp-content/plugins/advanced-ads-pro/assets/js/base.min.js
  • /wp-content/plugins/advanced-ads/public/assets/js/advanced.js

Make it better

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