Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Anti-flicker snippet timeout: fix the 4-second white page

PRF-020High impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

A/B testing tools change your page in the browser. Without protection, visitors can briefly see the original version before the variant swaps in. That jump is called flicker.

The anti-flicker snippet is a small piece of code placed in the <head>. It adds a CSS class to the <html> element that sets opacity: 0. The page is hidden. When the testing tool finishes, it removes the class and the page appears. If the tool never answers, a timeout removes the class anyway. The well-known Google Optimize snippet used 4000 ms (4 seconds). Other tools and custom copies use similar values.

Typical anti-flicker snippet (the 4000 is the timeout in ms)html
<style>.async-hide { opacity: 0 !important }</style>
<script>
(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
})(window,document.documentElement,'async-hide','dataLayer',4000,
{'GTM-XXXXXX':true});
</script>

Why it costs you leads or sales

Visitors from ads arrive with little patience. A white page for several seconds looks like a broken site, so some leave before they see your headline or form. Slow LCP can also hurt the page experience signals that Google measures, and slow landing pages can make paid traffic less efficient.

The damage is hidden. Your site is fast on your own laptop, where the tool loads quickly. It only fails on slow mobile connections, during an outage of the testing tool, or when an ad blocker stops the script. Those are the visitors who see 4 seconds of nothing.

LCP with and without a slow testing toolExample numbers
LCP with and without a slow testing tool (example)No anti-flicker snippet: 1.8 seconds; Snippet, tool fast: 2.4 seconds; Snippet, tool slow (4 s timeout): 5.2 seconds0241.82.45.2No anti-flicker snipp…Snippet, tool fastSnippet, tool slow (4…seconds

Example: the same page measured three ways. The hidden page cannot paint until the tool answers or the timeout ends.

What the visitor experiences
  1. Ad clickVisitor lands on the page
  2. HTML and CSS loadPage is ready to show
  3. Page hiddenopacity 0 until tool loads or 4 s passes
  4. Headline and formNot seen in time
  5. Lead or saleVisitor may have left

The page is ready early, but it stays hidden until the timeout.

How to check if your site has it

Find the snippet and test the delay
  1. View the page source

    Open the landing page, right-click, choose View page source and search for async-hide, opacity: 0 or anti-flicker. Also search for a number like 4000 near a setTimeout.

  2. Check Google Tag Manager and your testing tool

    Look in your A/B tool's settings for an 'anti-flicker' or 'page hiding' option. Some tools add it for you.

  3. Block the testing tool

    In Chrome DevTools, open the Network tab, right-click the testing script, choose Block request URL, and reload. If the page stays white for seconds, the timeout is hurting visitors.

  4. Throttle the connection

    In the Network tab choose a Slow 4G profile and reload. Watch how long the page stays blank.

  5. Record a Performance trace

    In the Performance tab, record a page load and check where LCP lands. A value close to your timeout is a strong sign.

How to fix it

Pick the first option that applies. Removing the snippet is safest when you no longer run visual tests. If you do run them, keep the snippet but cut the timeout so the worst case is short.

Remove or limit the page hiding
  1. Delete the snippet if no test needs it

    Remove the style block and script that add async-hide. This is the right fix for leftover Google Optimize code.

  2. Lower the timeout

    If you keep it, change 4000 to a value around 300-500 ms. Visitors then see the original page quickly if the tool is slow.

  3. Hide only what the test changes

    Instead of hiding the whole page, hide just the element being tested, for example .hero-headline. The rest of the page can paint and LCP stays early.

  4. Load the testing tool early and fast

    Place its script high in the <head>, serve it from the tool's recommended CDN snippet and avoid loading it through a delayed tag.

  5. Prefer server-side or redirect tests

    Tests that choose the variant before the page is sent need no hiding at all.

Hide only the tested element, with a short timeouthtml
<style>.fg-test-hide { opacity: 0 !important }</style>
<script>
document.documentElement.classList.add('fg-test-hide');
setTimeout(function () {
  document.documentElement.classList.remove('fg-test-hide');
}, 400);
</script>
Where to change it
  1. Find the tag

    In Tags, look for a Custom HTML tag containing async-hide or your testing tool's snippet.

  2. Edit or pause it

    Lower the timeout value, or pause the tag if it is leftover code. Preview the change, then Submit and publish the container.

How to confirm it's fixed

Confirmation checks
  • View source no longer shows a timeout above about 500 ms, or the snippet is gone
  • With the testing script blocked in DevTools, the page appears almost at once
  • On Slow 4G throttling, the headline and form show without a long white gap
  • LCP in a fresh Lighthouse or PageSpeed Insights run is back near your pre-test level
  • Your A/B tool still shows the variants, with no visible flicker you find unacceptable
Page behaviour when the testing tool is slow

Before

  • Whole page hidden with opacity 0
  • White screen for up to 4 s
  • LCP lands at the timeout
  • Visitors may leave before seeing the form

After

  • Timeout of about 400 ms, or no snippet
  • Page shows the original content quickly
  • LCP close to normal
  • Test still runs on the tested element

How to prevent it happening again

Habits that stop it coming back
  • Remove testing code when a test ends or the tool is retired
  • Keep one owner for the head code and review it each quarter
  • Set a maximum timeout of 500 ms in your team's testing guidelines
  • Test new experiments on throttled mobile before launching
  • Re-check LCP on paid landing pages after every new tool or tag is added
How a slow tool turns into a lost visit
  1. 0.0 s

    Example: the visitor clicks your ad and the page request starts

  2. 0.8 s

    HTML and CSS arrive, but the snippet has set opacity 0

  3. 2.0 s

    The testing script is still loading on a weak connection

  4. 4.0 s

    The timeout fires and the page finally appears

  5. 0.4 s (fixed)

    With a short timeout the page shows almost straight away

How FunnelGuard handles this

FunnelGuard detects this issue only partly. It checks LCP only: a robot visitor loads your funnel pages on a schedule and measures Largest Contentful Paint. If a slow testing tool and a long timeout push LCP up, that shows as a slow LCP and you get an alert with a screenshot and a likely cause.

FunnelGuard does not read your code to find the anti-flicker snippet, does not report the timeout value, and cannot tell you that the snippet is the cause of a high LCP. A fast testing tool can also hide the problem, because the delay only shows when the tool is slow or blocked.

Cover the rest by hand: search your page source for async-hide or opacity: 0, check the timeout number, and run the DevTools block-request test from the checking section above. Do this after any change to your testing tool. You can start with the Free plan (1 site, 2 journeys, daily checks, no card), and a free read-only website audit is available too.

Questions people ask

Why is my page white for 4 seconds before it shows?

A common cause is an anti-flicker snippet. It hides the page with opacity 0 until your A/B testing tool loads, and if the tool is slow, a fallback timeout of about 4 seconds ends the hiding. Check your page source for async-hide and the timeout number.

What is an anti-flicker snippet?

It is a small script in the page head that hides the page while an A/B testing tool prepares its changes. It prevents visitors seeing the original version flash before the variant. A timeout removes the hiding if the tool does not respond.

How do I reduce the anti-flicker timeout?

Find the number in the snippet, often 4000, and change it to about 300-500 milliseconds. In Google Tag Manager, edit the Custom HTML tag and publish. On other platforms, edit the theme or head code, then clear caches.

Can I just remove the anti-flicker snippet?

Yes, if you do not run visual A/B tests on that page. Without it, visitors may see a brief flicker on tested elements, but the page is never blanked. Leftover Google Optimize code should always be removed.

Does the anti-flicker snippet hurt LCP?

Yes. While the page is hidden, the browser cannot paint the main content, so LCP is pushed to when the hiding ends. A slow tool and a long timeout can add seconds.

Is Google Optimize still working?

No. Google ended Optimize in September 2023. Any remaining Optimize snippet only adds delay, so remove it and its container reference.

How do I test the anti-flicker delay myself?

Open Chrome DevTools, go to the Network tab, block the testing tool's script URL and reload the page. If the page stays white for seconds, the timeout is too long. Repeat on a Slow 4G throttle.

Can FunnelGuard detect an anti-flicker snippet?

Only partly. FunnelGuard measures LCP on your funnel pages, so a long delay can show up as a slow LCP. It does not identify the snippet or its timeout, so check the page source by hand.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: LCP only.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.