views:

358

answers:

3

According to Yahoo's "Best Practices for Speeding Up your Site", the pros for using iframes:

  • Helps with slow third-party content like badges and ads
  • Download scripts in parallel

but the cons are:

  • Costly even if blank
  • Blocks page onload

I want to use an iframe to load ads using the technique mentioned on this site: http://meanderingpassage.com/2007/08/15/keeping-javascript-widgets-from-controlling-your-blog/

Does using this technique mean that as soon as the html contents requested by the iframe are returned to the client, it will load the ad script, potentially blocking the rest of the page's rendering and downloading? Or will the iframe request get processed concurrently while rest of the document is downloaded and rendered?

I'm, however, not looking for a discussion on the philosophy of whether ads are good or bad.

+4  A: 

Rendering of the interior iframe is processed concurrently with the exterior page. Any javascript inside the iframe will only prevent loading of the contents inside the iframe.

Edit: also, I just noticed I answered your previous question on this subject, and as explained there it's possible to trigger iframe loading in javascript whenever you wish (e.g. after the rest of the page is loaded).

tloflin
@tloflin Thank-you. This is what I was trying to understand.
Cedar Jensen
+5  A: 

I'm not quite sure why the Yahoo list says "Blocks page onload". IFrames load independently of the parent page, particularly if the iframe content is in a different domain than the main page. The "Blocks page onload" seems contradictory to the pros, both of which are due to concurrency of the iframe load.

Now, if you have an iframe that is loading something from the same domain name as the main page, that may fall into the browser's connection limit per domain, and therefore impact how quickly the main page can download its content. But if the iframe URL is a different domain, it should get its own connection limit per domain.

The biggest pro for iframes is security isolation. When you load third party script into an iframe, you don't have to worry about the third party script taking over your page and scrawling graffitti all over the place, or stealing user data from your script variables.

The biggest con for iframes is also the security isolation. ;> The brick wall that protects you from third parties also makes it very difficult to communicate / share info between parties on the same web page.

dthorpe
+1 for context protection, though note for this to be secure you need to put the iframe on a different hostname. Otherwise you're still inviting the ad network and anyone they trust to cross-site-script into your security context; if they wanted to, they could control users' interaction with any page to do anything that user is authorised to do.
bobince
A: 

If you're putting in ads, you probably want to use AdSense (or at least test it out). The Google AdSense robot doesn't like iframes:
https://www.google.com/support/adsense/bin/answer.py?hl=en&answer=10035

nstory