Skip to content

Instantly share code, notes, and snippets.

@cdata
Created August 31, 2011 22:36
Show Gist options
  • Save cdata/1184926 to your computer and use it in GitHub Desktop.
Save cdata/1184926 to your computer and use it in GitHub Desktop.
Sample CloudFlareJS Configuration and Embeddable Snippets
<!-- CloudFlareJS live deployment snippet -->
<script type="text/javascript">
//<![CDATA[
/* Options reference
*
* verbose boolean Toggles verbose logging.
* p int Timestamp prior to which cached content is invalid.
* byc boolean Set to true to bypass local storage caching.
* bag string The path prefix for the bag endpoint.
* owl string The path prefix for the owl endpoint. Set falsey to disable.
* mirage boolean Set to true to enable dynamic image resizing.
* oracle string The path to site-specific static asset JSON. Set falsey to disable.
* paths object Map of module prefixes to path prefixes.
* atok string Action token for verifying backend requests.
* rocket boolean Set to true to enable Rocket Loader optimization.
* apps object Map of enabled app keys to associated settings.
*/
try {
if(!window.CloudFlare) {
var CloudFlare = [{
'verbose' : false,
'p' : 1238795439858,
'byc' : false,
'bag' : '/cdn-cgi/pe/bag',
'owl' : '/cdn-cgi/fast-stats',
'mirage' : false,
'oracle' : '/cdn-cgi/foobar/3iu4h5jkn345kjhaksijasd.json',
'paths' : {
'cloudflare' : '/cdn-cgi/nexp/v=29383944343/cloudflare/'
},
'atok' : '23l1kj3klj45h389dsffdadj4hk',
'rocket' : false,
'apps' : {}
}];
CloudFlare.push({/* Overrides go here.. */});
document.write('<script type="text/javascript" src="/cdn-cgi/nexp/v=432897432933/cloudflare.min.js"><' + '/script>');
}
} catch(e) {}
//]]>
</script>
<!-- Snippet for embedding CFJS synchronously -->
<script type="text/javascript">
//<![CDATA[
if(!window.CloudFlare) window.CloudFlare = [];
//]]>
</script>
<script type="text/javascript" src="//ajax.cloudflare.com/cdn-cgi/nexp/cloudflare.js"></script>
<!-- Snippet for embedding CFJS asynchronously -->
<script type="text/javascript">
//<![CDATA[
try {
if(!window.CloudFlare) {
window.CloudFlare = [];
(function() {
var cfjs = document.createElement('script'),
cursor = document.getElementsByTagName('script')[0];
cfjs.type = "text/javascript";
cfjs.async = true;
cfjs.src = "//ajax.cloudflare.com/cdn-cgi/nexp/cloudflare.js";
cursor.parentNode.insertBefore(cfjs, cursor);
})();
}
} catch(e) { try { console.error("CloudFlareJS could not be loaded. " + e.message); } catch(e) {} }
//]]>
</script>
<!-- Interacting with CloudFlareJS in an async-safe way -->
<script type="text/javascript">
//<![CDATA[
CloudFlare.push(
function(require, define) {
// CloudFlareJS is fully defined when this function is called.
}
)
//]]>
</script>
@cdata
Copy link
Author

cdata commented Jun 27, 2023

@xiaozhu2007 you're pointing to an old revision of the file that had typos. Either way, I wouldn't take this Gist as canonical documentation anymore; it's 12 years old and I haven't worked on CloudFlare.js in all of that time ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment