Skip to main content

What is anti-flickering script?

How the anti-flickering script works, the current snippet with a 2000 ms timeout, US and EU install tags, and WordPress plugin defaults.

7-min video demo

The anti-flickering script stops visitors from briefly seeing the original page before your test variant appears. That flash is called flicker. It is most noticeable when you change something above the fold, or when the Mida tag loads later than the page, for example through Google Tag Manager.

How it works

The script adds a white cover over the page as soon as it runs. The Mida tag removes that cover as soon as your variants have applied. If they have not applied by the timeout, the cover is removed anyway. The default timeout in the dashboard snippet is 2000 milliseconds. That value is a ceiling, not a delay.

Place the script in the <head> of the page, immediately before the Mida tag.

How to get the script

The easiest way is to copy it from your Mida dashboard. Go to Installation Guide, keep the anti-flickering option on, and copy the snippet. It already uses the right project key and the right region host.

You can also paste the snippet below. Use your own project key in place of YOUR_PROJECT_KEY. Use the US or EU tag that matches your account. Do not change the host. An EU account served the US host will load the script but will not run experiments.

Anti-flickering script

This is the current snippet. The default timeout is 2000 milliseconds.

<!-- Anti-flickering script -->
<script>
  var timeout = 2000; // Timeout value to remove the flicker (in milliseconds)
  !function(h,i,d,e){var t,n=h.createElement("style");n.id=e,n.innerHTML='body{position:relative;overflow:hidden}body::after{position:absolute;top:0;bottom:0;left:0;right:0;content:"";background:#fff;z-index:2147483647}',h.head.appendChild(n),t=d,i.rmfk=function(){var t=h.getElementById(e);t&&t.parentNode.removeChild(t)},setTimeout(i.rmfk,t)}(document,window,timeout,"abhide");
</script>

Example for US accounts

<!-- Anti-flickering script -->
<script>
  var timeout = 2000; // Timeout value to remove the flicker (in milliseconds)
  !function(h,i,d,e){var t,n=h.createElement("style");n.id=e,n.innerHTML='body{position:relative;overflow:hidden}body::after{position:absolute;top:0;bottom:0;left:0;right:0;content:"";background:#fff;z-index:2147483647}',h.head.appendChild(n),t=d,i.rmfk=function(){var t=h.getElementById(e);t&&t.parentNode.removeChild(t)},setTimeout(i.rmfk,t)}(document,window,timeout,"abhide");
</script>
<link rel="preconnect" href="https://api-us.mida.so" crossorigin>
<script type="text/javascript" async src="https://cdn.mida.so/js/optimize.js?key=YOUR_PROJECT_KEY"></script>

Example for EU accounts

<!-- Anti-flickering script -->
<script>
  var timeout = 2000; // Timeout value to remove the flicker (in milliseconds)
  !function(h,i,d,e){var t,n=h.createElement("style");n.id=e,n.innerHTML='body{position:relative;overflow:hidden}body::after{position:absolute;top:0;bottom:0;left:0;right:0;content:"";background:#fff;z-index:2147483647}',h.head.appendChild(n),t=d,i.rmfk=function(){var t=h.getElementById(e);t&&t.parentNode.removeChild(t)},setTimeout(i.rmfk,t)}(document,window,timeout,"abhide");
</script>
<link rel="preconnect" href="https://api-eu.mida.so" crossorigin>
<script type="text/javascript" async src="https://cdn-eu.mida.so/js/optimize.js?key=YOUR_PROJECT_KEY"></script>

WordPress

If you use WordPress or WooCommerce, install the Mida A/B Testing plugin from the WordPress plugin directory. That listing is the current version, 1.3.1.

From version 1.3, anti-flicker is on by default for new installs. If you update from an older version, your existing setting is kept. In the plugin settings, under Anti-Flicker Settings, you can turn it on or off. The default Max Timeout is 3000 ms. The default Post Delay is 0 ms.

For the full WordPress install steps, see How to install Mida on Wordpress/WooCommerce.

Best practices

  1. Use the script when your test changes something above the fold. Visitors will not notice flicker on changes below the fold.

  2. The script is most useful when flicker is obvious, or when the Mida tag is not in the page head.

Did this answer your question?