Your Web, Half a Second Sooner
At Google we’re constantly trying to
make the web
faster — not just our corner of it, but the whole thing. Over the past few days
we’ve been rolling out a new and improved version of show_ads.js, the piece of JavaScript used
by more than two million publishers to put
AdSense advertisements on their web pages.
The new show_ads is small and fast, built so that your browser can turn its attention back to
its main task — working on the rest of the web page — as soon as possible. This change is now
making billions of web pages every day load faster by half a second or more.
The old show_ads did lots of work: loading additional scripts, gathering information
about the web page it was running on, and building the ad request to send back to Google. The
new show_ads has a different job. It creates a friendly (same-origin) iframe on the web page,
and starts the old script with a new name, show_ads_impl, running inside that iframe. The
_impl does all the heavy lifting, and in the end the ads look exactly the same. But there’s a
substantial speed advantage: many things happening inside an iframe don’t block the web
browser’s other work.
How much of an effect this has depends on
context: a page with nothing but ads on it isn’t going to get any faster. But on the
real-world sites we tested, the latency overhead from our ads is basically gone. Page load
times with the new asynchronous AdSense implementation are statistically indistinguishable
from load times for the same pages with no ads at all.
The new show_ads
is a drop-in replacement for the old one: web site owners don’t need to do anything to get
this speed-up. But these
dynamically-populated
friendly iframes are finicky beasts. For now, we’re only using this technique on
Chrome, Firefox, and Internet Explorer 8, with more to come once we’re sure that it plays well
with other browsers.
And what if you’ve built a page that loads AdSense
ads and then manipulates them in exotic ways not compatible with friendly iframes? (This is
the web, after all, land of “What do you mean that’s ‘not supported’? I tried it, and it
worked!”) You can set “google_enable_async = false” for any individual ad slot to revert to
the old blocking behavior. But if your site loads ads in some tortuous way because you were
looking for latency benefits, consider giving the straightforward invocation of show_ads.js a
whirl. Because now, we’re fast.
By Michael Kleber, Ads Latency Team