Skip to main content
← Glossary · A/B Testing

Anti-Flicker Snippet

A small JavaScript snippet placed in the document head that hides page content until the A/B testing tool has loaded and applied the correct variant, preventing visible content flashes.

What Is an Anti-Flicker Snippet?

An anti-flicker snippet is a small piece of JavaScript (or CSS) placed early in the HTML document head that hides page content until the experimentation tool has loaded and applied the variant. It trades a brief blank state for a flicker-free variant reveal. Every major client-side testing platform (Optimizely, VWO, Google Optimize) provides one, and using it correctly is the single biggest quality improvement you can make to a client-side testing program.

Also Known As

  • Marketing teams call it the anti-flicker tag, pre-hide snippet, or hide snippet.
  • Growth teams say anti-flicker or FOOC prevention.
  • Product teams use pre-hide or variant guard.
  • Engineering teams refer to it as the anti-flicker snippet or async blocker.
  • Performance teams worry about it — they see it as a blocking script.

How It Works

The snippet sits in the document head and immediately applies `body { opacity: 0 !important }` (or similar). The testing platform loads, reads user assignment, modifies the DOM, then calls a function that removes the opacity style. If the testing script doesn't load within a timeout (say 4 seconds), the snippet auto-releases to prevent a stuck page. Net effect: user sees either a brief blank (50–300ms typical) followed by the variant, or — if the script fails — a delayed reveal of the original, not a flicker.

Best Practices

  • Place the snippet as the first script in the document head, before any other tags.
  • Set the timeout to match your testing script's 95th-percentile load time plus a safety margin.
  • Monitor your LCP impact — anti-flicker adds latency in exchange for eliminating flicker.
  • Don't pair anti-flicker with async loading of the testing script — it defeats the purpose.
  • Test the failure mode: deliberately block the testing script and confirm the page still reveals on timeout.

Common Mistakes

  • Placing the snippet below other scripts, letting paint occur before hide kicks in.
  • Setting a too-long timeout (8 seconds+), creating a blank page that inflates bounce rate.
  • Using anti-flicker without configuring the "release" callback, leaving the page hidden indefinitely if the tool fails.

Industry Context

  • SaaS/B2B: Critical on dashboard and app surfaces where flicker looks like a bug.
  • Ecommerce/DTC: Standard on high-traffic PDPs and checkout pages.
  • Lead gen: Essential on mobile landing pages where slow connections make flicker most visible.

The Behavioral Science Connection

Anti-flicker leverages the psychology of waiting vs. changing. A brief blank is processed as "loading" — users wait patiently. A visible content change is processed as "something weird happened" — users become vigilant. By converting a change into a wait, you preserve cognitive ease and experiment validity.

Key Takeaway

An anti-flicker snippet is mandatory for any serious client-side testing program — the alternative is biased data and worse UX.