Forum Moderators: open

Message Too Old, No Replies

Iframes VS XMLHttpRequest

         

charlee

7:41 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



I have been digging around trying to find some info about this topic and as a summary this is what i found:

------------------ XHR ------------ iFrame
Multithread:------ yes ------------ no
Back button------- no ------------ yes
Cross-site-------- no ------------ yes
Statuses---------- yes ------------ no

I would like to know some opinions about this and some specific examples where using an iframe will be better than using the XMLHttpRequest, im sure more than one person have some doubts about this :)

thanks in advance

httpwebwitch

9:02 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As your chart illustrates, XHR and iFrame are vastly different beasts. It's akin to asking when to use a car or a horse. Where does one start? There are a few things both do well - request a URL - but the similarity stops shortly thereafter.

iframe: use it when you really want a browser-within-a-browser experience. Or when you need a resource to be pinged (like, for tracking purposed) but Javascript is disabled.
iframe is also a very effective placenta around content you don't want a parent page to manipulate, especially when the content is on a different domain.

XHR: use it when you're doing AJAX in any of its various modern flavours. Also good for Lazy Loading, Predictive Fetch, and other techniques.

This is just scratching the surface of a huge topic

charlee

10:56 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



I got it, but still i would like to know who do u think is the horse and who is the car?

httpwebwitch

11:45 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



XHR is the car, of course

daveVk

12:39 pm on Apr 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cross-site-------- no ------------ yes

Whilst you can get content cross domain into an iframe, security will prevent access to it from host page and vice versa.

So if we are taking about using a hidden iframe for AJAX functionality there is no cross site advantage. XMLHttpRequest also allows POSTS, so unless very early browser support is an issue it is the best way to go.