Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the different between Ajax and Web Worker in Javascript?

I think they almost do the same thing. What's the condition that we should choose Web Worker than Ajax?

like image 758
EasonBlack Avatar asked Nov 19 '12 14:11

EasonBlack


People also ask

What is a web worker in JavaScript?

A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background.

What is the difference between service worker and web worker?

Unlike web workers, service workers allow you to intercept network requests (via the fetch event) and to listen for Push API events in the background (via the push event). A page can spawn multiple web workers, but a single service worker controls all the active tabs under the scope it was registered with.

What is a web worker used for?

Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering with the user interface.

How many web workers can run concurrently?

A web worker is a JavaScript program running on a different thread, in parallel with main thread. The browser creates one thread per tab. The main thread can spawn an unlimited number of web workers, until the user's system resources are fully consumed.


1 Answers

AJAX is specifically for communicating with a server, whereas web workers are a for background processing.

While AJAX is asynchronous (by default), this is not to be confused with a "concurrent" model of background processing that web workers offer.

A web worker could be any process and is not restricted to client-server communication.

like image 198
Diodeus - James MacFarlane Avatar answered Oct 12 '22 22:10

Diodeus - James MacFarlane