We’ve migrated our documentation to a new site, which means some URLs have changed.
Audience

Details on High-Performance Javascript Implementation

Information on how our asynchronous scripts work, and the efforts we make to have the ad serving as quick as possible:

The script snippet a publisher copies onto his page looks like this (formatted for readability):

<script type="text/javascript">
    (function() { try {
        var scriptEl = document.createElement('script'); scriptEl.type = 'text/javascript'; scriptEl.async = 'async';
        scriptEl.src = ('https:' == document.location.protocol) ? 'https://scdn.cxense.com/cx.js' : 'http://cdn.cxense.com/cx.js';
        var targetEl = document.getElementsByTagName('script')[0]; targetEl.parentNode.insertBefore(scriptEl, targetEl);
    } catch (e) { }; } ());
</script>
<script id="scriptForAdSpace_000000000031068f" type="text/javascript">
    var cX = cX || {}; cX.callQueue = cX.callQueue || [];
    cX.callQueue.push(['insertAdSpace', { adSpaceId: '000000000031068f', adUnitWidth: 728, adUnitHeight: 90, initialHorizontalAdUnits: 1, initialVerticalAdUnits: 1}]);
</script>     
  1. This script can be put anywhere in the body of the page. It does not have any remote script references, so it does not block any rendering.

  2. The top part of the script adds the reference to our external script programmatically. This causes the browser to load this script in parallel, and the rendering is not blocked.

  3. In addition to the programmatic insertion of the script, you can see that we set “scriptEl.async = 'async'“ to also take advantage of modern browsers ability to load and execute the script asynchronously.

  4. The source of our external script is set to cdn.cxense.com/cx.js or scdn.cxense.com/cx.js depending on whether the page is served over https or not.

  5. We use geo-local DNS lookups for the name (s)cdn.cxense.com, so that the DNS lookups will be as quick as possible

  6. We use geo-local CDN for distributing the script so that all your users will get a geo-local download server, again to make the download as quick as possible

  7. Both cdn and scdn support gzip encoding, minimizing the amount the browser needs to download, which is especially important for mobile users.

  8. The external script is completely static, and cached hard. In most cases, the browser will have this script in its cache already, and it will not need to be downloaded.

  9. The bottom part of the script sets up the calls that we want to make. In this case, it is a call to insert ads into the page. As you can see, all calls are queued, as we load our external script asynchronously, and the methods might not be available to call at this time. The queued method calls are all executed in the inserted sequence as soon as the external script has loaded, or immediately if the script was cached (most common case)

  10. For the ad insertion, the external script creates an iframe within the document, so that the external ad request can be handled in parallel with the rendering of the page. This insertion of the iframe is the only modifications to the DOM we make, and it does not block the rendering of the page, as the iframe content loads and renders in parallel to the parent page. 

Last updated: