Stack Overflow站点如何执行非常快的Ajax功能?

时间:2022-10-07 15:58:26

I was wondering and very much curious that How Stack Overflow site is executing very very fast Ajax like functionalities?

我很好奇堆栈溢出站点是如何像函数一样快速执行Ajax的?

Because if see at the voting system, comments, answers, approve edits, edits in answer and questions.

因为如果在投票系统中看到,评论,回答,批准编辑,在回答和问题中编辑。

All these are working so fast I couldn't imagine that How SO executes these things very very quick. Because in our general scenario if we make Ajax Request it takes few seconds to respond but not in case of SO.

所有这些都运行得如此之快,我无法想象如何执行这些东西的速度如此之快。因为在我们的一般场景中,如果我们发出Ajax请求,需要几秒钟的时间来响应,但在这种情况下不会。

How this happens?

这是如何发生的?

Edit: for those who voted it to close

编辑:对于那些投票结束的人

Here my intention is only for technical person. And I am not asking to show a code How SO is written. My concern is the mechanism which SO has implemented.

这里我的目的只是为技术人员。我并不是要告诉你如何编写代码。我所关心的是实施的机制。

1 个解决方案

#1


3  

In general, SO uses web sockets to provide responsive, fast updates. If you want to learn more, have a look at, on example, socket.io (which is a nice wrapper for web sockets providing fallback for older browsers) or MDN doc on websockets. You can also go all-in and read the RFC.

一般来说,SO使用web套接字提供响应迅速的更新。如果你想了解更多,看看插座。io(它是为旧浏览器提供备用的web套接字的好包装)或websockets上的MDN文档。您也可以全部进入和阅读RFC。

Here is a sample request (from Chrome Developer Tools):

下面是一个示例请求(来自Chrome开发工具):

Request URL:ws://sockets.ny.stackexchange.com/
Request Method:GET
Request Headersview source
Cache-Control:no-cache
Connection:Upgrade
Host:sockets.ny.stackexchange.com
Sec-WebSocket-Extensions:x-webkit-deflate-frame
Sec-WebSocket-Key:PcP0d7X/j2DJkw2mx+116w==
Sec-WebSocket-Version:13
Upgrade:websocket

And response:

和响应:

Status Code:101 Switching Protocols
Connection:Upgrade
Sec-WebSocket-Accept: ...
Upgrade:websocket

#1


3  

In general, SO uses web sockets to provide responsive, fast updates. If you want to learn more, have a look at, on example, socket.io (which is a nice wrapper for web sockets providing fallback for older browsers) or MDN doc on websockets. You can also go all-in and read the RFC.

一般来说,SO使用web套接字提供响应迅速的更新。如果你想了解更多,看看插座。io(它是为旧浏览器提供备用的web套接字的好包装)或websockets上的MDN文档。您也可以全部进入和阅读RFC。

Here is a sample request (from Chrome Developer Tools):

下面是一个示例请求(来自Chrome开发工具):

Request URL:ws://sockets.ny.stackexchange.com/
Request Method:GET
Request Headersview source
Cache-Control:no-cache
Connection:Upgrade
Host:sockets.ny.stackexchange.com
Sec-WebSocket-Extensions:x-webkit-deflate-frame
Sec-WebSocket-Key:PcP0d7X/j2DJkw2mx+116w==
Sec-WebSocket-Version:13
Upgrade:websocket

And response:

和响应:

Status Code:101 Switching Protocols
Connection:Upgrade
Sec-WebSocket-Accept: ...
Upgrade:websocket