你是如何实现youtube评论功能的?

时间:2020-12-31 18:57:04

How is youtube comments feature implemented? I see that they use AJAX but they don't do AJAX calls every second or two.Ajax call is made when there is a new comment on the video. On my page I call a page every 5 seconds with AJAX. So how are they doing that?

你是如何实现youtube评论功能的?我看到他们使用AJAX,但他们不会每隔一两次进行AJAX调用。当视频有新评论时,会调用Ajax。在我的页面上,我每隔5秒使用AJAX调用一个页面。那他们是怎么做到的?

2 个解决方案

#1


1  

Personnally when i have a look at Firebug to see Ajax Request, i have one who's called every 2-3 seconds with parameters :

当我看到Firebug看到Ajax请求时,我有一个每隔2-3秒用参数调用的人:

asv    3
ctp    2
docid      DbYtqAWDF2U
el     detailpage
et     20.087
fmt    34
ns     yt
plid       AASgAO8pqC5GDlo9
st     20.087
vid    VcyzE1TkaJrg4jlA8I_rWIK6z2TaXNB3R
yttk       1

docid is just the id of the video, $_GET['v'] var too.

docid只是视频的ID,$ _GET ['v'] var也是如此。

#2


0  

It uses Ajax and if you see the content of the ajax call it contains poll_delay value which is something like 60,000 which means when it has to poll the live comments again.60 seconds in this case.

它使用Ajax,如果你看到ajax调用的内容,它包含poll_delay值,类似于60,000,这意味着它必须再次轮询实时注释。在这种情况下为60秒。

#1


1  

Personnally when i have a look at Firebug to see Ajax Request, i have one who's called every 2-3 seconds with parameters :

当我看到Firebug看到Ajax请求时,我有一个每隔2-3秒用参数调用的人:

asv    3
ctp    2
docid      DbYtqAWDF2U
el     detailpage
et     20.087
fmt    34
ns     yt
plid       AASgAO8pqC5GDlo9
st     20.087
vid    VcyzE1TkaJrg4jlA8I_rWIK6z2TaXNB3R
yttk       1

docid is just the id of the video, $_GET['v'] var too.

docid只是视频的ID,$ _GET ['v'] var也是如此。

#2


0  

It uses Ajax and if you see the content of the ajax call it contains poll_delay value which is something like 60,000 which means when it has to poll the live comments again.60 seconds in this case.

它使用Ajax,如果你看到ajax调用的内容,它包含poll_delay值,类似于60,000,这意味着它必须再次轮询实时注释。在这种情况下为60秒。