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?
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.
When browsers start to implement web sockets.
I'm somewhat skeptical. All major browsers started supporting ajax in 1999, and it gained popularity somewhere around 2005, after the launch of gmail. And we've not even reached that point yet, where major browsers support websockets (add another couple of years).
There's a simple reason behind that delay in ajax adoption: need for websites to support older browser versions. (Remember, how many people still use IE 6&7?)
精彩评论