Ajax、Web sockets和Web Workers

时间:2022-09-11 22:29:33

What is the difference between all three? They seem to do the exact same thing. Why and when would you choose to use one method over the other?

这三者的区别是什么?他们似乎在做同样的事情。为什么以及何时选择使用一种方法而不是另一种方法?

3 个解决方案

#1


30  

AJAX and websockets do similar tasks — they both establish a communication channel to a server. Web workers have nothing to do with either of them, they are just separate threads of JS execution.

AJAX和websockets执行类似的任务——它们都建立了一个到服务器的通信通道。Web工作人员与这两者都没有关系,它们只是JS执行的独立线程。

AJAX is more mature than websockets — it has been around much longer and has a much wider browser support. AJAX is request-oriented — you make a request to the server, the server responds, and the connection is closed. Websockets on the other hand establish a persistent connection to the server, over which you exchange multiple messages in both directions.

AJAX比websockets更成熟——它已经存在了很长时间,并且有更广泛的浏览器支持。AJAX是面向请求的——您向服务器发出请求,服务器响应,连接被关闭。另一方面,Websockets建立了一个与服务器的持久连接,你可以在两个方向上交换多个消息。

Webworkers are useful if you want to perform a processor intensive task without blocking the browser interface.

如果您希望在不阻塞浏览器界面的情况下执行处理器密集型任务,那么webworker是非常有用的。

#2


11  

They are not the same.

它们不一样。

Ajax: It is a way of interacting with a web server asynchronously from a UI renderer

Ajax:它是一种从UI渲染器异步与web服务器交互的方式。

Web Sockets: An HTML5 feature using which you can interact with any Socket server extending the reach of the browser

Web Sockets:一个HTML5特性,您可以使用它来与扩展浏览器的任何Socket服务器进行交互。

Web Workers : Another HTML5 feature that helps you do multi-threaded programming from a web browser using Java Script

Web worker:另一个HTML5特性,它可以帮助您使用Java脚本从Web浏览器进行多线程编程

#3


10  

They are not same. But one can use them together to build advanced application.

它们不是相同的。但是可以将它们结合在一起构建高级应用程序。

Ajax: As abbrevation States is asynchronous javascript and xml.. is used to load the content dynamically from the server upon called.

Ajax:由于分离状态是异步javascript和xml。用于在调用时从服务器动态加载内容。

Websockets : Websockets is the feature defined in HTML5 . As wikipedia states "WebSocket is a protocol providing full-duplex communications channels over a single TCP connection." so this is mainly used for real time communication such as video call, live chat etc..

Websockets: Websockets是HTML5中定义的功能。正如*所说,“WebSocket是一种协议,它提供了一个TCP连接上的全双工通信信道”,因此这主要用于实时通信,如视频通话、实时聊天等。

WebWorkers : this feature is also defined in HTML5. This is basically used to make bring multi threading feature in Javascript. Since javascript is a single threaded programming language , it breaks or pause whenever i.e heavy calculation tasks are done using it. to overcome this breakage , Webworkers are added to javascript.

webworker:这个特性在HTML5中也有定义。这主要用于在Javascript中引入多线程特性。由于javascript是一种单线程编程语言,所以每当我使用它时,它就会中断或暂停。大量的计算任务都是用它来完成的。为了克服这种缺陷,将webworker添加到javascript中。

You can perform Ajax and Websockets inside Webworkers . however you cannot manipulate DOM using webworkers due to security reasons.

您可以在webworker中执行Ajax和Websockets。但是,由于安全原因,您不能使用webworker操作DOM。

#1


30  

AJAX and websockets do similar tasks — they both establish a communication channel to a server. Web workers have nothing to do with either of them, they are just separate threads of JS execution.

AJAX和websockets执行类似的任务——它们都建立了一个到服务器的通信通道。Web工作人员与这两者都没有关系,它们只是JS执行的独立线程。

AJAX is more mature than websockets — it has been around much longer and has a much wider browser support. AJAX is request-oriented — you make a request to the server, the server responds, and the connection is closed. Websockets on the other hand establish a persistent connection to the server, over which you exchange multiple messages in both directions.

AJAX比websockets更成熟——它已经存在了很长时间,并且有更广泛的浏览器支持。AJAX是面向请求的——您向服务器发出请求,服务器响应,连接被关闭。另一方面,Websockets建立了一个与服务器的持久连接,你可以在两个方向上交换多个消息。

Webworkers are useful if you want to perform a processor intensive task without blocking the browser interface.

如果您希望在不阻塞浏览器界面的情况下执行处理器密集型任务,那么webworker是非常有用的。

#2


11  

They are not the same.

它们不一样。

Ajax: It is a way of interacting with a web server asynchronously from a UI renderer

Ajax:它是一种从UI渲染器异步与web服务器交互的方式。

Web Sockets: An HTML5 feature using which you can interact with any Socket server extending the reach of the browser

Web Sockets:一个HTML5特性,您可以使用它来与扩展浏览器的任何Socket服务器进行交互。

Web Workers : Another HTML5 feature that helps you do multi-threaded programming from a web browser using Java Script

Web worker:另一个HTML5特性,它可以帮助您使用Java脚本从Web浏览器进行多线程编程

#3


10  

They are not same. But one can use them together to build advanced application.

它们不是相同的。但是可以将它们结合在一起构建高级应用程序。

Ajax: As abbrevation States is asynchronous javascript and xml.. is used to load the content dynamically from the server upon called.

Ajax:由于分离状态是异步javascript和xml。用于在调用时从服务器动态加载内容。

Websockets : Websockets is the feature defined in HTML5 . As wikipedia states "WebSocket is a protocol providing full-duplex communications channels over a single TCP connection." so this is mainly used for real time communication such as video call, live chat etc..

Websockets: Websockets是HTML5中定义的功能。正如*所说,“WebSocket是一种协议,它提供了一个TCP连接上的全双工通信信道”,因此这主要用于实时通信,如视频通话、实时聊天等。

WebWorkers : this feature is also defined in HTML5. This is basically used to make bring multi threading feature in Javascript. Since javascript is a single threaded programming language , it breaks or pause whenever i.e heavy calculation tasks are done using it. to overcome this breakage , Webworkers are added to javascript.

webworker:这个特性在HTML5中也有定义。这主要用于在Javascript中引入多线程特性。由于javascript是一种单线程编程语言,所以每当我使用它时,它就会中断或暂停。大量的计算任务都是用它来完成的。为了克服这种缺陷,将webworker添加到javascript中。

You can perform Ajax and Websockets inside Webworkers . however you cannot manipulate DOM using webworkers due to security reasons.

您可以在webworker中执行Ajax和Websockets。但是,由于安全原因,您不能使用webworker操作DOM。