简体   繁体   English

Facebook通过iframe拨打AJAX电话吗?

[英]Facebook makes their AJAX calls through iframe?

I want to implement AJAX like facebook, so my sites can be really fast too. 我想像Facebook一样实现AJAX,所以我的网站也可以非常快。 After weeks of research and also knowing about bigPipe (which is not ajax). 经过数周的研究,并且也了解了bigPipe(不是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 any such request and but still page gets loaded with AJAX and changes the HTML also, firebug does show change on html. 但是问题是,firebug不会记录任何这样的请求,但是页面仍然加载了AJAX并更改了HTML,firebug的确显示了html的更改。

So I'm wondering, if they are using iframe to block firebug to see the request or what? 因此,我想知道,他们是否正在使用iframe阻止Firebug来查看请求或什么? 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. 他们之所以使用iframe,通常是出于安全考虑。 iframes are like new tabs, there is no communication between your page and the iframe facebook page. iframe就像新标签一样,您的页面与iframe facebook页面之间没有任何交流。 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). iframe具有自己的cookie和会话,因此实际上您需要像其他窗口一样思考它,而不是自己页面的一部分(除了输出明显显示在页面内的事实)。

That said - the developer mode in chrome does show you the communications to and from the iframe. 就是说-chrome中的开发人员模式确实向您显示了与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. 当我单击Facebook上的用户个人资料时,然后在Firebug中,我清楚地看到了对数据的请求是如何发生的,以及div的内容如何变化。 So, what is the question about? 那么,问题是什么呢?

After click on some user profile, Facebook does following GET request: 单击某些用户个人资料后,Facebook会执行以下GET请求:

    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. 该请求的响应是一个复杂的JS数据,其中包含构建新页面的所有必要信息。 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.). 个人资料的朋友数组(带有名称,头像缩略图链接等),个人资料的最后一个条目数组(同样,带有缩略图URL,注释等)。

There is no magic, no something like code hiding or obfuscation. 没有魔术,没有代码隐藏或混淆之类的东西。 =) =)

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 :- 如果您了解bigPipe,那么您将能够理解这一点,因为您已阅读有关big pipe的内容,它们的响应如下所示:-

<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, 因此,如果他们使用ajax,则将无法使用bigpipe,这意味着如果他们使用ajax和一台服务器来刷新缓冲区,则在客户端上不会产生任何影响,ajax oncomplete仅在接收到完整数据并关闭连接后才调用,否则话说,他们将无法使用那里最好的页面速度技术之一,

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 :- 但是,如果他们将iframe用于ajax,该怎么做,他们可以在iframe中使用其大管道,服务器将像这样发送数据:-

<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. 因此服务器可以刷新缓冲区,并且只要缓冲区被清除,浏览器就可以获取,这在ajax情况下是不可能的。

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. 他们仅在页面URL更改时才使用iframe,这意味着当需要下载包含小页面的新页面时,对于其他请求(如某些弹出框或通知等),他们会简单地发送ajax请求。

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! ) 所有信息都是非官方的,实际上我正在对此进行研究,所以我发现,(我不是英语为母语的人,对您的拼写和语法错误感到抱歉!)

通过谷歌浏览器查看人脸书,他们使用ajax请求文件返回JavaScript,然后将其用于对页面进行任何更改。

I don't know why/wether Facebook uses IFRAMEs to asynchroneously load data but I guess there is no special reason behind that. 我不知道Facebook为什么/是否使用IFRAME异步加载数据,但我想这背后没有特殊原因。 We used IFRAMEs too but now switched to XMLHttpRequest for our projects because it's more flexible. 我们也使用了IFRAME,但是现在因为项目更灵活,所以切换到XMLHttpRequest用于我们的项目。 Perhaps the IFRAME method works better on (much) older browsers, but even IE6 supports XMLHttpRequest fine. 也许IFRAME方法在(许多)较旧的浏览器上效果更好,但即使IE6也支持XMLHttpRequest。

Anyway, I'm certain that there is no performance advantage when using IFRAMEs. 无论如何,我确定使用IFRAME时没有性能优势。 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. 如果您需要快速异步数据加载来动态更新页面,请使用XMLHttpRequest,因为任何现代浏览器都支持XMLHttpRequest,并且它的速度与HTTP一样快。

当您单击其他配置文件时,facebook不会使用ajax加载配置文件,您只需简单地打开一个新链接即可获取纯旧的html ...,但也许我误会了您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM