Tuesday, April 4th, 2006

PHPClasses.org Chooses iFrames over Ajax?

Category: Ajax, Programming

When people first look at what Ajax really is it seems like they’re either immediately turned off by it or jump in with both feet. Of course, there are a few in the middle – they look into Ajax to provide some functionality for their site and just don’t find quite what they’re looking for. They fall back on what they’re used to and what works for them – the traditional iframe.

One such example of this is referenced in this new post on the PHPClasses blog dealing with Manuel Lemos’ choice to go with iframes instead of XMLHttpRequest for the updated version of his site, PHPClasses.org.

This AJAX plug-in that I developed does not use XMLHttpRequest objects. It uses an hidden IFrame instead. Some people consider that AJAX only refers to browser-server interaction done with XMLHttpRequest objects. That detail should not matter because IFrame can be used for the same purposes.

What I would like to share with you are the reasons why I have chosen IFrame over XMLHttpRequest objects.

Some of his reasons include: “Browser compatibility”, “Browser security constraints”, and “Response speed”. He bases his decision on the results from a presentation he attended that stated Ajax was fine for small requests, but an iframe can handle larger requests more easily and faster than its counterpart. He also mentions another reason for his decision – a mention that, with an Ajax connection, one can only get to the data once the request is complete, versus an iframe that can send back chunked data. A few other items were mentioned such as the ability to perform multiple actions in one request and that there’s no direct method to handle file uploading.

Posted by Chris Cornutt at 7:26 am

3.4 rating from 47 votes


Comments feed TrackBack URI

According to Emil XMLHttpRequest is faster than using IFrames. However I do see his point in regards to browser compability.

Comment by Espen Antonsen — April 4, 2006

I’m sorry to diverge from the topic at hand, but Manuel Lemos makes the most horrible looking sites on the web. Granted site design isn’t his main focus, but after coming from this beautiful looking site, it simply hurts my eyes. IFrames or XMLHttpRequest should be his concern, but rather a new color scheme.

Comment by Dan Allen — April 4, 2006

PHPclasses.org is not just ugly, it is also difficult to use, poorly organized and, well, I think the design can be summed up in a phrase: “blinking, animated gifs.”

Comment by chris feldmann — April 4, 2006

Maybe it’s one of those ugly = user-friendly things that are so big these days.

Comment by Dan — April 4, 2006

The hoops you have to jump through to download the code are a reason I usually avoid phpclasses.org — I’m usually disapointed in the code quality also (it’s no CPAN, that’s for sure).

For some reason, the live comment updating on ajaxian is making the google ad on the bottom right jump all over the page (as part of the reflow?) Typing this comment is taking forever because of that.

Comment by Andy — April 4, 2006

I was about to say that his site’s design is irrelevant … but then I looked (heh) and I do get the impression he isn’t a guy who “gets” usability.

That said, maybe he needs to deal with some really old browsers.

Comment by Joe Grossberg — April 4, 2006

Browser compatibility? The only browser that has given me serious issues with AJAX would be IE 5. Mozilla, IE 6+, Netscape* are all good. That said, if anybody is even still using IE 5, please, do webmasters a favor and update!

*Raise your hand if you actually know anyone who uses Netscape as their primary browser…no one? What a surprise…

Comment by Michael Jackson — April 4, 2006

Where is the X in his approach. What he does is merely an RPC, outputting javascript. He is not outputting XML. Even in those cases, you’d better be off using an dynamically inserted .js file.

Comment by M. Schopman — April 4, 2006

I’ve used the XMLHttpRequest object as well as the hidden Iframe approach, going back as far as 1999. I’ve used “Ajax” extensively since, and my current feeling is that the Iframe method usually wins in most cases. XMLHttpRequest object is good if i need data that has to be frequently updated (like an aggressive setTimeout data transfer), so that it won’t constantly refresh the little ‘loading’ bar in IE. Otherwise, I prefer using the hidden Iframe because it lets me bring in HTML, JavaScript, XML, raw data, whatever, and i can process the results using the parent script, or the resulting data in the iframe can have it’s own javascript that will process what it needs to do accordingly. It is much more flexible and useful than just XMLHttpRequest alone. I do use it a lot for large form data post-backs to the server as well. XMLHttpRequest is still good if all you want to do is pass small bits of data to or from a browser on a frequent basis.

Comment by damien — April 4, 2006

I’ll add another vote to the “ajaxian” category. Let’s (supposedly) “save time” with iframes and then make you spend 10 minutes logging in and selecting a mirror. phpclasses.org gives sourceforge.net a run for its money when it comes to clicks-to-result.

Comment by Robb Irrgang — April 4, 2006

And there’s really no excuse for iframe vs ajax unless you’re trying to support IE5/Mac (like I have to do on a paper company website that apparently has a lot of users that are clinging to their G4’s with OS 9, Quark 4.11, and IE5). There is no excuse for a Windows user to use IE5/Win and at that point the site should be pointing out the insane obseleteness (not a word, I know) of that p.o.s. browser.

OS 9 users have no real “upgrade” from IE5/Mac.

Comment by Robb Irrgang — April 4, 2006

I’ve used iframe for years, and it requires browser specific code as well. More than XmlHttpRequest. But the author contradicts himself when he first writes:

IFrame is more widely supported among all browsers, even in older versions.

And then he says you need modern browsers for iframe:

IFrame is an HTML tag consistently supported across all modern browsers.

If you need modern browsers for XmlHttpRequest and for IFrame, what’s the point of difference here??

Comment by Berend de Boer — April 4, 2006

I am so glad I switched to rails… I never have to use that website again :)

Comment by Jenna Fox — April 4, 2006

Actually, to comment on the Netscape thing. We use @mail as the mail system for all our hosting customers. One guy called up pissed that it didnt work right and he told me he uses Netscape. I asked if they even made the browser anymore. That was the first time in 2 years of hosting customer support I heard someone reference Netscape. I tool him to get FireFox and he proceeded to cuss me out and hang up. Heh.

Comment by Jason — April 4, 2006

Thank you Chris for commenting about this PHPClasses blog post. An user of the PHPClasses site brought to my attention about your post. I appreciate everybody’s comments, as it gives me the opportunity to clarify aspects that may have been misunderstood. So I will take this opportunity to clarify some aspects.

First off all, the use of an IFrame is just for RPC. The IFrame is hidden. It will not be seen by the user. The actual page updating, when necessary is done via DHTML, changing innerHTML of some the page element parts.

I also did not base my decision to use hidden IFrame versus XMLHttpRequest on a presentation that I attended. The presentation was promoting XMLHttpRequest.

I questioned the conclusions of the presentation because it is always good to reflect and ask yourself if the latest technology fashions is necessarily the best. I concluded that IFrame is better than XMLHttpRequest for my purposes, but I respect people with different opinions, specially those opinions are well justified.

The detail about the benchmarks that were presented in the session, considered only making complete requests. With IFrame, I may get partial response made of JavaScript blocks with tags that get executed right away, even if the browser did not complete to load the whole hidden IFrame page. You cannot achieve this with XMLHttpRequest.

Using multiple JavaScript blocks with separated tags in the same response, you can also give progress feedback, while the whole response does not come. This is demonstrated by the test_ajax_form.php example that comes with this PHP forms class.

Regarding browser compatibility, note that not everybody uses the latest version of each browser. Even if 99% use a capable browser, those remaining 1% can give you an headache when it come to time and patience that it takes to answer to their support calls.

Even when you decide to be harsh, and tell “sorry I do not support your browser”, you still need to spend time doing that in a polite way that people understand and accept, and sometimes you do not succeed.

Regarding the aesthetics comment, I should remind you that it is impossible to please everybody. As I mentioned in a past newsletter, what is ugly for some, it may be nice or even irrelevant to others.

Since you can’t please everybody with a single design, the ideal solution is to let users configure aspects of the presentation that they can tweak to become satisfied.

Unfortunately it is not viable to provide personalization control to every user. It would easily compromise the site scalability. Scalability is currently achieved by caching the pages HTML on the server. Even with intensive use of CSS, it would not solve all personalization aspects.

Also, re-factoring the site to provide proper personalization control will give me a lot of work to compensate giving it priority to that task, if it was meant to be made available free for all.

The PHPClasses site is not a big portal like Yahoo or Google with hundreds of engineers developing many complex features at once. Some people do not imagine, but the PHPClasses site is just me and the hundreds of developers that submit their classes to the site.

Therefore, presentation personalization will be made available only to subscribers of the premium services package that I already mentioned in the site newsletters several times.

Not everybody will want to pay to benefit from this and other enhancements, but at least those that want it will have an option. Some people disagree with paid features, but once they run a site like this, maybe they understand why not everything can be made available free for all.

Thank you,
Manuel Lemos

Comment by Manuel Lemos — April 4, 2006

I use both, iframes and XMLHTTP. – I have to admit though, my reasons for doing so are different.

I’ve developed a comprehesive extranet system in the old clunky non-AJAX style (~800 ASP files, ~100 PHP files) and… rather than re-write everything using AJAX… I just stripped out everything but the core content on all the other pages… making ‘edit’,’delete’,etc. function pages just appear in an IFRAME which is positioned over the existing page’s content in a div layer. (When these forms [or dialogues] are submitted, a javascript callback tells the first page to hide the dialogue IFRAME and take further action (DOM manipulation, etc.)

I’ll re-write using AJAX sometimes (file lists, custom formats, etc.)… but when it comes to retrieving “dialog boxes” that are essentially a webpage where you POST data to another page.. I just cheat and use the IFRAMEs. ;)

Comment by method — April 5, 2006

It looks like this.

Comment by ax — April 5, 2006

PHPClasses is awful. For some reason I am constantly having to re-login and I get that nice “portal” login page that I have to go through after logging in before I can get what I want. And yes, it’s ugly. It’s slow, it’s full of ads, it uses tables for formatting and bgcolor=”” width=”” on table cells. In other words, it looks like it was made in 1999.

Frankly, the “it’s just me! (and 100’s of contributors)” is not a very good argument. How many developers did it take to create, say, Mint?

How long do you suppose it would take one person to replicate the functionality (with those cute AJAX-y effects) in Rails? Or PHP for that matter?

Comment by Tex Texerson — April 5, 2006

I agreed with Lemos’ decision. I presented the seminar he watched, and I made some tests and also commented Emil A. Eklund’s test (pointed by Espen Antonsen).

Espen: Read the full paragraph. Emil says that XMLHttpRequest is faster than IFrame for small requests. Not in all cases; check this info by looking at his result graphs. =)

For a variety of purposes IFrame has advantages over XMLHttpRequest. But it’s not the best for all purposes… XMLHttpRequest has other advantages too, and I can post a 13 thousand words comment explaining why this or that in one or other methodology.
I just want to highlight that important changes in big websites are calculated and not followed by buzzwords that we see daily.

I also agreed that his website’s layout is horrible… I already met him phisically, and one of the first things I’ve told him is the ugly green he uses. =D

Whatever, instead of just point your opinions, try to think why this or that decision was took… there’s probably a reason for this.


Comment by Guilherme Blanco — April 5, 2006

“with an Ajax connection, one can only get to the data once the request is complete”

??? Bull cocky !!!


Are we all so framework dependent tha we don’t know how javascript works? Of course you can access the data before the request is complete, what do you think all those readySate==4 checks are for?

Comment by arantius — April 6, 2006

There is one comment from the post that nobody has mentioned yet and yet it’s the most grossly inaccurate statement I have heard about XMLHttpRequest.

XMLHttpRequest is NOT affected by the new Microsoft ActiveX patch. There is no reason it would be, since it has no interface of it’s own. Wherever this information came from in first place should be suspect.

Personally I prefer not jumping through the hoops necessary to determine that a document is loaded into an iframe before scooping up the data (if anyone knows of a good library for this please speak up).

Still the iframe method has it’s place. I’ve used both and pick and choose on situation. DOM3 load and save may ennd up being better than either but it’s not here yet.

Comment by Chris C. Root — April 18, 2006

amen. I have been a longtime fan of phpclasses, but have to agree its been ugly since birth.

Comment by trioptic — April 20, 2006

It frustrates me that there are many kind people out there that are willing to share their classes and code snippets and Manuel Lemos feels the need to drag users through a god-awful interface and popup ads in order to download them.

I am going to create a new php class repository that looks pretty, and contains NO adverts!

Please go to http://www.webgrub.co.uk and add your name/email to join the mailing list.

Please pass on the word as I will need a very large mailing list before launching the site, or it will simply never pick up!

I look forward to hearing from you!
Kind Regards,
Toby de Havilland.

Comment by toby de havilland — May 31, 2006

It frustrates me that there are many kind people out there that are willing to share their classes and code snippets and Manuel Lemos feels the need to drag users through a god-awful interface and popup ads in order to download them.

I am going to create a new php class repository that looks pretty, and contains NO adverts!!

Please go to http://www.webgrub.co.uk and add your name/email to join the mailing list.

Please pass on the word as I will need a very large mailing list before launching the site, or it will simply never pick up!

I look forward to hearing from you!
Kind Regards,
Toby de Havilland.

Comment by toby de havilland — May 31, 2006

Leave a comment

You must be logged in to post a comment.