开发者

Facebook makes their AJAX calls through iframe?

开发者 https://www.devze.com 2023-02-19 15:59 出处:网络
I want to implement AJAX like facebook, so my sites can be really fast too. After weeks of research and also knowing about bigPipe (which is not ajax).

I want to implement AJAX like facebook, so my sites can be really fast too. After weeks of research and also knowing about bigPipe (which is not ajax).

so the only thing left was how they are pulling other requests like going to page/profile, I opened up firebug and was just checking things there for what I get if I click on different profiles. But the problem is, firebug doen'tt record an开发者_如何学Pythony such request and but still page gets loaded with AJAX and changes the HTML also, firebug does show change on html.

So I'm wondering, if they are using iframe to block firebug to see the request or what? Because I want to know how much data they pull on each request. Is it the complete page or only a part of page, because page layout changes as well, depending on the page it is (for example: groups, page, profile, ...).

I would be really grateful if a pro gives some feedback on this, because i cant find it anywhere for weeks.


The reason they use iframe, usually its security. iframes are like new tabs, there is no communication between your page and the iframe facebook page. The iframe has its own cookies and session, so really you need to think about it like another window rather than part of your own page (except for the obvious fact that the output is shown within your page).

That said - the developer mode in chrome does show you the communications to and from the iframe.


When I click on user's profile at facebook, then in Firebug I clearly see how request for data happens, and how div's content changing. So, what is the question about?

After click on some user profile, Facebook does following GET request:

    http://www.facebook.com/ajax/hovercard/user.php?id=100000655044XXX&__a=1

This request's response is a complex JS data, which contain all necessary information to build a new page. There is a array of profile's friends (with names, avatar thumbnails links, etc), array of the profile last entries (again, with thumbnails URLs, annotations, etc.).

There is no magic, no something like code hiding or obfuscation. =)


Looking at face book through google chromes inspector they use ajax to request files the give back javascript which is then used to make any changes to the page.


I don't know why/wether Facebook uses IFRAMEs to asynchroneously load data but I guess there is no special reason behind that. We used IFRAMEs too but now switched to XMLHttpRequest for our projects because it's more flexible. Perhaps the IFRAME method works better on (much) older browsers, but even IE6 supports XMLHttpRequest fine.

Anyway, I'm certain that there is no performance advantage when using IFRAMEs. If you need fast asynchroneous data loading to dynamically update your page, go with XMLHttpRequest since any modern browsers supports it and it's fast as HTTP can be.


If you know about bigPipe then you will be able to understand that, As you have read about big pipe their response look like this :-

<script type="text/javascript">  bigpipe.onPageArrive({ 'css' : '', '__html' : '  ' }); </script>

So if they ajax then they will not able to use bigpipe, mean if they use ajax and one server they flush buffer, on client there will no effect of that, the ajax oncomplete only will call when complete data received and connection closed, In other words they will not able to use their one of the best page speed technique there,

but what if they use iframe for ajax,, this make point,, they can use their bigpipe in iframe and server will send data like this :-

<script type="text/javascript">   parent.bigpipe.onPageArrive({ 'some' : 'some' });

so server can flush buffer and as soon as buffer will clear, browser will get that, that was not possible in ajax case.

Important :-

They use iframe only when page url change, mean when a new page need to be downloaded that contains the pagelets, for other request like some popup box or notifications etc they simple send ajax request.

All informations are unofficial, Actually i was researching on that, so i found, ( I m not a native english speaker, sorry for spelling and grammer mistakes! )


when you click on different profile, facebook doesn't use ajax for loading the profile you simple open a new link plain old html... but maybe I misunderstood you

0

精彩评论

暂无评论...
验证码 换一张
取 消