What is AdLibs?
Small differences in features between browsers can have a great impact on how your site performs. Sites like caniuse.com allow developers to determine each browser’s featuresets and thus develop their script accordingly. AdLibs utilizes these browser-specific features to determine the user’s environment and safely perform a task across all browsers.
What does it do?
AdLibs.js uses feature detection to return information about the client’s environment, including browser and OS data. AdLibs also allows the user to perform front end tasks such as XMLHttp and JSONP requests, url parsing, and performance measurement using high performance navigation apis, when available.
For website publishers, user agents should be used to detect how a user intends to interact with and experience their site. Almost every browser detection script available today takes this into account and provides detection based on these user and application changeable strings. This poses a problem for reliable market share analysis tools and troubleshooting. The AdLibs library utilizes feature API detection as a mechanism for detecting the true device or webview version an ad or script is embedded within. This functionality is best when used in a clean iframe window where native methods have not been munged by polyfill functionality. Knowing how polyfill libraries can affect a page, AdLibs is both dependency free and uses no polyfills, leaving the embedding page unaffected.
Feature detection is key in distinguishing between browser versions. For example, the navigator.permissions property is only available after Chrome 43 and window.indexedDB was only available on Safari after 7.1. As a tool primarily used when serving ads, AdLibs is also able to detect the context in which an ad is served, such as frame depth and ad size. It’s detection modules include:
- Browser and OS detection
- Environment detection - detects environment context (e.g. screen size, flash version, etc.)
- Mraid - can return the version of MRAID as well as execute a given function when mraid is ready
- Safeframe - returns Safeframe metrics (specVersion, getInfo support, etc.)
AdLibs uses its feature detection to safely execute browser-side functions. For example, XMLHttpRequest isn’t supported on all browsers. Specifically, older versions of Internet Explorer use ActiveXObjects to wrap HTTP requests. AdLibs contains its own XMLHTTPRequest wrapper to account for the difference in behavior between browsers. Other supported operations include jsonp requests,
AdLibs also allows developers to measure the performance of their script. AdLibs is able to build a report from the currently available page performance data. For optimal results, make sure the debug panel is closed prior to running any performance test and open it to view the results in the console afterward. There are performance penalties on all scripts running when the inspector panels of browsers are open during script execution.
Why the funky name?
Aside from sounding like mad libs, AdLibs is a common library used by the ad-client team at Conversant to retrieve market share and browser environment and feature support information for use in light weight, high performance scripts. We use the tool to return info about the user’s device and context of the ad.
For more information
Conversant AdLibs is on github