Why we should avoid iframe?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Since it is part fo the standard, why I always heard that we should
avoid iframe?

any comments?


Re: Why we should avoid iframe?

howa wrote:

Quoted text here. Click to load it

Depends which standard you're referring to. The <iframe> element only
exists in HTML 4.01 Loose, and in XHTML 1.0 Transitional and Frameset.

The part about avoiding <iframe> really applies to all uses of frames.
There are, for the most part, better ways to include shared content
than using frames (including <iframe>).

Kim André Akerĝ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)

Re: Why we should avoid iframe?

howa wrote:
Quoted text here. Click to load it

Exactly. None of the problems with frames listed in the FAQ* have anything
to do with browser support or whether frames are part of any given
specification, and all are equally applicable to inline frames.

And some of us find that disabling inline frames (at least for unknown,
untrusted sites) is an effective way to reduce annoying ads and other
stupid web tricks.

* http://www.htmlhelp.com/faq/html/frames.html#frame-problems
Darin McGrew, mcgrew@stanfordalumni.org, http://www.rahul.net/mcgrew /
    Web Design Group, darin@htmlhelp.com, http://www.HTMLHelp.com /

"Do not look where you fell, but where you slipped." - African Proverb

Re: Why we should avoid iframe?

Quoted text here. Click to load it

Why do you need an <iframe> ?  Is there a better way of doing it ?
I'd generally avoid it in favour of something better, but I wouldn't
rule it out altogether.

As a minor issue, <iframe> isn't in all of the doctypes. This is no
reason to not use <iframe>, but if you're going to use it anyway, at
least choose a doctype for which it's valid.

There are several potential reasons that you might use <iframe>, some
better than others.

 * To wrap some changing content up in a constant menu structure
(typical frame usage)

 * To statically include boilerplate text

 * For AJAX-like purposes involving HTML data sources rather than XML
(e.g. screen-scraping from HTML pages)

The first of these is perhaps the most commonplace. It has the great
advantage (like all frames techniques) of simplicity, and the
disadvantage of many small drawbacks. Overall, it's best avoided. In
practice, it's worth knowing about and still worth using if you don't
have the time / needs / skills to build something better.

It's particularly useful if you have a client-side "report viewing"
page with a single embedded report that's chosen from a list on the
container page (just as an example). Trivial HTML coding gives you a
selectable list or reports that appear in-line on the same page.  It's
particularly useful if it's a set of _files_ that you're viewing here,
rather than documents from a web server (so you don't have the option
to use server-side coding). I have dozens of these myself, reporting
on the current status of our many products. Python scripts and XSLT
generate the report pages and the index page, then they're linked by
an <iframe>. Moving this to a web server would be a problem (for other
reasons), so it suits me to just keep them on the filesystem. If
they're only there as static files, I'm restricted in the techniques I
can use, but <iframe> still works.

The second is really a "poor man's SSI". Avoid this. Avoid this
strongly, in favour of real SSI. Any competent hosting offers SSI, so
use it (or move to hosting that does allow it).

My current project uses a vast numbe of legacy <iframe>s, as a poor
substitute for JSP tag libraries. This separates "technical web
coders" from "application coders" who each work on separate files.
It's arguably better than having everyone dive into one large and
uncontrollable shared file, but the real solution would be a neat use
of tag libraries, not this client-side aggregation of page sections.

The third is interesting. AJAX is widely popular now, but the "X" in
AJAX stands for XML not HTML and so it's impossible to use this
technique with a non-XML HTML page, or a non well-formed XHTML page.
XmlHttpRequest et al only work for parsing XML documents. The work-
around is to use an <iframe> and to dynamically load new content into
it with client-side JavaScript. The <iframe> (and the browser) act as
your HTML parser. The <iframe> can of course be hidden from display,
just used from program code.

<iframe> also has efficiency issues, as it represents two HHTTP
requests to assemble a page that can probably be supplied through just
one (if assembled server-side first). That's a very minor point though
- any typical page will have a great many separate requests
regardless, <iframe>s are one of the last places to start counting and
optimising these away.

Re: Why we should avoid iframe?

Andy Dingley wrote:

Quoted text here. Click to load it

I wrote an AJAX chat that uses no XML or XHTML. The data passed to the
web page does not have to be XML. It can be anything that Javascript can
parse into valid HTML (or XHTML, depending on your DocType).

Re: Why we should avoid iframe?

Quoted text here. Click to load it

So is that AJAX, or "AJAX-like asynchronous JavaScript using an
alternative parser"?  Purely a terminology point.

Quoted text here. Click to load it

It does if you're going to use XMLHttpRequest with it. If you don't,
then you can use anything you can build a parser for. For HTML, that
may well be an <iframe>.

Re: Why we should avoid iframe?

Quoted text here. Click to load it

there are two strong reasons:

1. solve the cross-domain problem
2. make the original page cachabale

Site Timeline