Snippet Deployment Models
The problem: a slow snippet causes flicker
Section titled βThe problem: a slow snippet causes flickerβWeb Experimentation applies changes by modifying the DOM before the page renders. If the snippet loads too slowly, visitors see the original page briefly before the variation appears β a visible flash called βflicker.β Flicker degrades user experience and can bias experiment results because visitors notice the change happening.
Snippet deployment strategy determines how fast the snippet reaches the browser, how cacheable it is, and how much control you have over updates. Choosing the right model is the difference between invisible experiments and noticeable page jank.
Deployment models
Section titled βDeployment modelsβCDN hosting (default)
Section titled βCDN hosting (default)βOptimizely hosts the snippet on its global CDN at cdn.optimizely.com. You add a <script> tag to your siteβs <head>, and the snippet loads from the nearest CDN edge node.
Advantages:
- Zero infrastructure to manage
- Automatic updates when you publish experiment changes
- Global edge network for low-latency delivery
Trade-offs:
- Third-party domain means the browser must perform a DNS lookup and TLS handshake for
cdn.optimizely.com - Some ad blockers and privacy tools block requests to
cdn.optimizely.com - You cannot control cache headers or HTTP/2 prioritization
This is the right choice for most teams getting started. It works immediately and requires no server-side configuration.
CDN with custom domain
Section titled βCDN with custom domainβYou configure a CNAME record so the snippet loads from a subdomain you control (e.g., optly.yoursite.com) while still being served by Optimizelyβs CDN infrastructure.
Advantages:
- Same-origin or first-party subdomain avoids most ad blocker issues
- DNS lookup can be pre-resolved if the subdomain shares the parent domain
- No infrastructure to manage on your side
Trade-offs:
- Requires DNS configuration and SSL certificate provisioning
- Still a separate domain from your main site, so connection reuse is limited
Custom domains are a good middle ground β you get the reliability of Optimizelyβs CDN without the third-party domain penalty.
Self-hosting
Section titled βSelf-hostingβYou download the snippet file and serve it from your own infrastructure, alongside your other static assets.
Advantages:
- Same-origin delivery eliminates the extra DNS lookup and TLS handshake entirely
- Full control over cache headers, HTTP/2 push, and bundling
- No ad blocker interference (the file lives on your domain)
- Can be included in your existing asset pipeline
Trade-offs:
- You must update the snippet file whenever experiment configuration changes. This can be automated with the Optimizely REST API or webhooks, but it is your responsibility.
- If you bundle the snippet with other JavaScript, a snippet update requires a full redeploy
- Stale snippets serve outdated experiment configurations
Synchronous vs. asynchronous loading
Section titled βSynchronous vs. asynchronous loadingβHow you load the snippet matters as much as where you host it.
Synchronous loading (no async attribute) pauses HTML parsing until the snippet executes. This eliminates flicker because variation changes apply before the page renders. The trade-off is that a slow-loading snippet delays the entire page.
Asynchronous loading (with async) lets the page render while the snippet loads in the background. This avoids blocking but introduces flicker risk. Use async only when you have another flicker-prevention mechanism in place, such as Performance Edge.
Snippet size management
Section titled βSnippet size managementβSnippet size directly affects load time. A 200 KB snippet takes longer to download and parse than a 50 KB snippet, especially on mobile networks.
Factors that increase snippet size:
- Number of active experiments β Each experiment adds configuration data
- Complex audience conditions β Custom JavaScript audiences add code to the snippet
- Variation code β Custom JavaScript in variations is bundled into the snippet
- Historical experiments β Paused or archived experiments may still be included if not properly cleaned up
To keep the snippet lean:
- Archive experiments you are no longer analyzing
- Use URL targeting instead of complex JavaScript audience conditions where possible
- Move heavy variation logic to your own codebase and use the Optimizely API to trigger it
- Monitor snippet size in the Optimizely dashboard under project settings
Decision framework
Section titled βDecision frameworkβ| Factor | CDN (default) | Custom domain | Self-hosted |
|---|---|---|---|
| Setup effort | None | DNS + SSL config | Build pipeline integration |
| Ad blocker resilience | Low | High | Highest |
| Update latency | Instant | Instant | Manual or webhook-driven |
| Performance | Good | Better | Best (same-origin) |
| Tier requirement | All tiers | All tiers | Enhanced+ |
For most teams, start with CDN hosting. Move to a custom domain if ad blockers are impacting your experiment reach. Graduate to self-hosting when you need maximum performance control and have the infrastructure to automate snippet updates.