Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will websockets in HTML 5 replace ajax for partial page refreshes?

Tags:

html

ajax

I've just stumbled upon the websockets feature coming in HTML 5, here. At first glance it seems that once Firefox and IE get on board with the spec ajax may be redundant. My question is, in your opinion will ajax (using jquery $.ajax() or even with straight XMLHttpRequest/other) be replaced by this new ws:// protocol?

If so, when should we start changing our development methodologies?

like image 901
Tahbaza Avatar asked Jul 02 '10 04:07

Tahbaza


1 Answers

Websockets address a different need than XMLHTTPRequests. The latter is what its name says: a request: You know that you need something (ie. because the user clicked a link, scrolled or whatever) and you retrieve it - and XHR does a fine job doing just that.

Trouble starts when certain events can be triggered on the serverside that are supposed to be pushed to the client in realtime. The only thing that you can do right now is to poll the server on a regular basis - which is a hack that comes with a set of problems. And this is exactly the problem that Websockets are made for: To provide a backchannel to the browser for realtime notifications.

I think Ajax XOR Websockets is kind of a false dichotomy. They address different needs and can coexist peacefully.

like image 152
flitzwald Avatar answered Sep 19 '22 03:09

flitzwald