P3PC is a project to review the performance of 3rd party content such as ads, widgets, and analytics. You can see all the reviews and stats on the P3PC home page. This blog post looks at BuySellAds.com. Here are the summary stats:
||JS ungzip||DOM elems||median Δ
|Click here to see how your browser performs compared to the median load time shown above.|
After signing up for BuySellAds.com, you can setup different types of ads. I chose an image-only 125×125 ad. Since this is a test page, I can’t get real ads. Check out Webdesigner Depot or All Things Cupcake to see some real ads. The folks at BuySellAds.com set me up with a test ad for demo purposes. Here’s what the test ad looks like. (This is a static image. Go to the Compare page to see the snippet live.)
Let’s look at the actual snippet code:
|1:||<!– BuySellAds.com Ad Code –>|
|4:||var bsa = document.createElement(‘script’);|
|6:||bsa.async = true;|
|7:||bsa.src = ‘//s3.buysellads.com/ac/bsa.js’;|
|8:||(document.getElementsByTagName(‘head’) || document.getElementsByTagName(‘body’)).appendChild(bsa);|
|11:||<!– END BuySellAds.com Ad Code –>|
|12:||<!– BuySellAds.com Zone Code –>|
|13:||<div id=”bsap_1245700″ class=”bsarocks bsap_84a5f8f4c8e4c1bb2c57948fba2d9cc4″></div>|
|14:||<!– END BuySellAds.com Zone Code –>|
A quick walk through the snippet code:
- lines 3-9 – Dynamically load the bsa.js script.
- line 13 – Create a DIV to hold the ad.
This HTTP waterfall chart was generated by WebPagetest.org using IE 7 with a 1.5Mbps connection from Dulles, VA. Let’s step through each request.
- item 1: compare.php – The HTML document.
- item 2: bsa.js – The main script. This is loaded dynamically, so it doesn’t block other downloads.
- item 3: *-waterfall.png – The waterfall image in this page. This is the main content of the page. Notice how it loads in parallel with bsa.js.
- item 4: s_84a5f8f4c8e4c1bb2c57948fba2d9cc4.js – A JSON response containing the ad content. This resource was added dynamically by bsa.js.
- item 6: 18446-1268342919.png – The image contained in the test ad.
- item 7: imp.gif – A beacon.
The amazing thing about the BuySellAds.com snippet is that it loads ads asynchronously. Most web developers are familiar with the performance delays inflicted by ads with scripts that block the main content in the page, or even worse scripts that use document.write so any hope of parallelization is dashed. BuySellAds.com is the only ad snippet that I’ve seen that avoids these blocking issues. (If you know of others, please add a comment mentioning them.)
Asynchronous loading is achieved as a result of two things:
- dynamically loading bsa.js (as opposed to using normal SCRIPT SRC HTML tags)
- creating a DIV placeholder for the ad content (as opposed to using document.write)
Loading ads asynchronously is a big advantage of BuySellAds.com. But there are still a few more performance improvements that could be made.
1. The size of the DIV changes causing the page to re-layout.
I used WebPagetest.org to create a filmstrip of images showing the page loading. Notice how the waterfall chart appears at 1.5 seconds. At 2.0 seconds the ad is loaded causing the waterfall chart to shift downward. It would better if the snippet set the DIV’s width and height to the appropriate values for the selected ad size.
2. bsa.js isn’t cached.
This is the script that publishers add to their pages. As such, it has to have a short expiration time so that the file cached by users is updated frequently. However, no expiration date causes browsers to check for updates too frequently. A 1 day or 1 week expiration date would strike a better balance between performance and update frequency.
3. The beacon returns a 200 HTTP status code.
I recommend returning a 204 (No Content) status code. A 204 response has no body and browsers will never cache them, which is exactly what we want from a beacon. In this case, the image body is less than 100 bytes, and the beacon’s HTTP headers prevent it from being cached. Although the savings are minimal, using a 204 response for beacons is a good best practice.
Hats off to the folks at BuySellAds.com for showing that asynchronous ads are possible. I’ll examine a few more ad snippets in the coming weeks. We’ll see how they stack up when it comes to performance.
Other posts in the P3PC series: