Skip to content

Instantly share code, notes, and snippets.

@jbmoelker
Created February 3, 2017 10:43
Show Gist options
  • Save jbmoelker/83b62e9df6e75d24a870ec1287fbb1ea to your computer and use it in GitHub Desktop.
Save jbmoelker/83b62e9df6e75d24a870ec1287fbb1ea to your computer and use it in GitHub Desktop.
Load Optimizely async
/**
* Inline this into the <head> of your HTML document. Replace `PROJECT_ID` and optionally change timeout (now 1000ms).
*
* Based on https://help.optimizely.com/Set_Up_Optimizely/Synchronous_and_Asynchronous_snippet_loading
* Simplified for today's browsers (no `s.async` or `s.type` needed, no need to prefix with `window.`).
* Note: risk of using `document.appendChild`: https://www.paulirish.com/2011/surefire-dom-element-insertion/
*/
(function(d) {
var s = d.createElement('script');
s.src = 'https://cdn.optimizely.com/js/PROJECT_ID.js';
d.head.appendChild(s);
setTimeout(function() {
var o = optimizely = optimizely || [];
o.data || o.push('timeout');
}, 1000);
})(document);
!function(a){var b=a.createElement("script");b.src="https://cdn.optimizely.com/js/PROJECT_ID.js",a.head.appendChild(b),setTimeout(function(){var a=optimizely=optimizely||[];a.data||a.push("timeout")},1e3)}(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment