Facebook如何立即初始化最近的新闻提要条目? [英] How facebook initializes recent news feed entries instantly?

查看:93
本文介绍了Facebook如何立即初始化最近的新闻提要条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的Web项目开发一个新闻提要模块.新闻提要活动(帖子,过滤器等)与Facebook几乎相似.当用户向下滚动页面(无限滚动)时,我使用了分页模式来逐页初始化新闻(例如:每滚动20条帖子).

I am developing a news feed module for my web project. News feed activities (post, filter, etc.) are nearly similar to Facebook. I ve used pagination pattern that initializes news page by page (eg: 20 post for every scroll) when user scrolls the page down (unlimited scrolling).

我想知道当您的一个朋友分享一个帖子时,Facebook如何初始化当前新闻. 我猜它使用一个触发器,该触发器发送ajax请求以获取是否存在新帖子.使用计时器触发器(具有每10秒发送ajax请求的javascript超时功能)将不是解决此问题的有效方法.

I wonder how Facebook initializes current news when one of your friends shares a post. I guess it uses a trigger that sends an ajax request to get if new posts are exist. Using a timer trigger (with javascript timeout function which sends ajax requests every 10 seconds) would not be an effective solution for this problem.

有人对我有其他触发建议吗?

Does anyone have any other trigger advices for me ?

预先感谢.

推荐答案

如果要监视主页的网络活动,您会看到对https://pct.channel.facebook.com/pull的调用,并附加了一些唯一的参数.观看时,您会看到通话花费了可变的时间长度,从1秒到〜60秒.

If you were to monitor the network activity of the home page, you'd see calls to https://pct.channel.facebook.com/pull with some unique parameters attached to it. While watching it you'd see that the calls take a variable length of time, from 1 second to ~60 seconds.

这称为长期投票,服务器在其中等待直到获得新信息可用于发回响应.同时,HTTP调用处于挂起状态,就像端点正在加载一样.服务器找到可用的信息后,它将发送带有数据的响应,并关闭连接.然后,客户端一旦接收到数据,便会通过另一个HTTP调用重新打开连接.

This is referred to as Long-Polling, where the server waits until new information is available to send back a response. Meantime, the HTTP call is held in suspense as though the endpoint is loading. Once the server finds information available, it sends a response with the data, and closes the connection. Then the client re-opens the connection with another HTTP call once it receives data.

这篇关于Facebook如何立即初始化最近的新闻提要条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆