iFrames – dos and donts

January 2, 2008

iFrame scripting has been underrated for a long period of time, i guess because it was assimilated to frame navigation. It just sounded a too chaotic way of scripting Web Pages and a gateway for malicious coding. With the emergence of Ajax, iFrames are now back in our HTML sources. Why is that so?

Segment the information

A web page can contain quiet an amount of informations. Web masters want as much content as possible in one page: RSS feeds, comment forms, image slide show -just name it. The only problem is that if one item of the page needs to be reloaded, all the others will be, because a web page is seen as an entire and non-dividable entity.

sports.fr is a French Web Site about soccer. They have a RSS feed on each page. To make sure information is updated frequently and accurate, they reload the RSS module every minute or so – but since everything is linked in a Web Page, the whole page refreshes itself. If you are reading an article – users comments included, the page will automatically reload two or three times, so you end up spending 5 or more minutes in a page that would require only 1 or 2 minutes of reading time. What if RSS module could reload itself without reloading the whole page? That’s where iFrame scripting comes handy.

I heard iframes are not w3c-compliant

If you script in XHTML, iframe is not recommended by W3C. Yet, its utility is more related to JavaScript than it is to XML. Google is also reluctant to iframes and says it could ignore documents containing iframes because they are not “well-formed”, yet it will still index the iFrame if specified in the robot.txt.

With all due respect to both w3c and the Goog, iframes have proved to be quiet useful right now as a transitional state to more elaborate HTTP requests inside a document. As it is, an iframe is expected to be a HTML document with HTML as a root element and HEAD and BODY as children, when most of the times, we don’t need to generate an HTML document, but just a piece of code whose server queries will be independent from parent document. Javascript tricks and XMLrequest, once more elaborated and cross-platform, will replace the iframes. Nonetheless, as today, iFrame is a quick and efficient solution to program fast and user-friendly Web applications.