โ† Back to Rules

๐Ÿงช Cloudflare Snippets A/B Testing Demo

Demonstrate edge-side A/B testing using Cloudflare Snippets

View in Dashboard โ†’

๐ŸŽฏ A/B Testing Control Loading...

Enable or disable the A/B testing snippet. When enabled, visitors to /demo will be randomly assigned to variant A or B with persistent cookie tracking.

๐Ÿ“Š How It Works

Cloudflare Snippets run at the edge before your origin is reached. This demo shows how to use snippets for A/B testing:

  • Snippet checks for existing variant cookie
  • If none exists, randomly assigns variant A or B (50/50 split)
  • Uses HTMLRewriter to inject variant-specific content
  • Sets cookie to persist assignment across sessions
  • All processing happens at the edge - zero origin load

๐Ÿš€ What are Cloudflare Snippets?

Snippets are lightweight JavaScript functions that run at Cloudflare's edge, allowing you to modify requests and responses before they reach your origin or users.

Learn more about Snippets โ†’