On Thursday, as the world was looking to the internet for information about Michael Jackson, the internet came to a crawl. The initial assumption was that news sites simply weren’t equipped to handle the spike in traffic that such an event would cause. Even Google News flagged the surge as an automated attack. According to a report by Keynote Systems, the news sites were fine, but their advertising partners weren’t.
Most of the time ads (like Google AdSense) are embedded on a website as an iframe widget. Iframes make integrating ads and other outside content as easy as copy-pasting a chunk of code into your page. When the user visits your site, the page containg the iframe is returned and as the browser renders the page it fetches the ad content from the outside party. Most of the time everything zips along and you never really notice or care about the order in which things happen.
What really happens is that each iframe the browser encounters starts the loading process for that iframe immediately. The iframe and external resources are requested, potentially using up all of the browser connections (if the iframe is from the same hostname). Possibly most important of all is that the window load event is delayed until all of the iframes have completed loading. So while your page may have finished long ago, any javascript code you have waiting for the load event will still be waiting for the iframes. And if your advertising partner’s network is buried under the weight of the world wanting to know about Michael Jackson, that could be a long time. So while the news sites themselves were equipped to handle the surge, it appeared to the visitors that the sites were extremely slow.
Now this isn’t just limited to news sites and advertisement networks. Social networking widgets suffer the same potential problems. The social network platform Ning blocked a widget provider for technical degredations to the network and Facebook has been known to contact developers of poorly performing applications.
But there are a few ideas from Steve Souders for reducing the impact iframe widgets have on your site.
- If you host the widgets (and referenced data) yourself, your site will never be slow because of widgets. The site will go up or down as a whole.
- You can leave out the src attribute of the iframe and set it with javascript when your page’s content is loaded. In some browsers this allows the window load event to fire without waiting for the iframes.
- In the end, Souders says “When possible, avoid iframes. When necessary, use them sparingly.”


