Skip to main content

How to Exclude A/B Testing Script from WP Rocket's JavaScript Optimizations

WP Rocket's JavaScript optimization features can interfere with Mida if not configured correctly.

Mida's script needs to run as early as possible in <head> to assign visitors to experiment variants before the browser paints the page. When WP Rocket delays or bundles it, visitors see a flash of the original content before any experiment fires.

The three WP Rocket settings that can affect Mida

WP Rocket feature

Why it breaks Mida

Minify / Combine JavaScript

Bundles Mida's script into a combined file, moving it out of <head>

Load JavaScript Deferred

Adds defer — script runs after HTML is parsed, too late for variant assignment

Delay JavaScript Execution

Holds all scripts until user interaction — Mida never fires on page load

How to exclude Mida

Go to WordPress Admin → Settings → WP Rocket → File Optimization.

For each of the features above, find its Excluded JavaScript Files field and add: optimize.js

  • Under Minify JavaScript / Combine JavaScript → Excluded JavaScript Files

  • Under Load JavaScript Deferred → Excluded JavaScript Files

  • Under Delay JavaScript Execution → Excluded JavaScript Files

Not sure which features are active? Add optimize.js to all three. Adding it to a disabled feature has no effect.

File Optimization tab - WP Rocket

Also exclude the anti-flicker inline script

If you're using Mida's anti-flicker snippet, add this to the Delay JavaScript Execution → Excluded JavaScript Files field as well: abhide

After saving, click Clear Cache in WP Rocket.

Clear cache on whole site

Go to SettingsWP RocketDashboard tab and press the Clear and preload cache button.

Clear and preload cache button

Another way is via the WordPress tool bar (or admin bar). Roll over the WP Rocket menu link, and you will see a dropdown menu. Click on the Clear and preload cache link.

Clear and preload cache menu

Skip all of this with the Mida WordPress plugin

The Mida A/B Testing plugin handles all of the above automatically. Install it from the WordPress plugin directory and it will take care of the correct script setup, no manual WP Rocket configuration needed.

Did this answer your question?