JavaScript: From Closures to Autonomous Systems

Capítulo 14. Meteor: The Application as One System

Part IV. Distributed Reactivity7 min · en inglés

14

Meteor: The Application as One System

From the very beginning the web had one limitation nobody thought about for a long time: the browser always starts the conversation. It sends a request, the server answers, and there the conversation ends. If the server has something new, say a chat message has arrived or someone has changed a document, it cannot tell the browser until the browser asks. So the first «live» pages simply asked every few seconds whether there was anything new. The answer was almost always «no», almost all the traffic went to these empty questions, and the news still arrived late, at the next question.

In March 2006 Alex Russell, the lead of the Dojo library, wrote a blog post giving a name to a set of techniques some developers were already using by then. He called them Comet. The simplest was called long polling: the browser sends a request, the server takes its time answering and keeps the connection open until data appears, answers, and the browser immediately sends the next request. Cleverer was the hidden-frame technique. The page opened a frame that never finished loading, and the server every now and then appended bits of script to it, which the browser executed as soon as it received each one. Both techniques worked, but on the servers of the time every open connection occupied a thread or a process, and a thousand users waiting for news meant a thousand sleeping threads. Three years later Ryan Dahl would run into the same difficulty and put it on his slides when presenting Node. And Russell himself, in 2012, together with Wirfs-Brock, would lead the discussion of the «maximally minimal classes» from the second chapter.

The real solution came in December 2011, when the WebSocket standard was published. The browser opens a connection once, and from then on both it and the server can write to it whenever they like. But browsers did not learn this at once, and proxies and corporate networks kept breaking such connections for a long time, so libraries became popular that tried to open a WebSocket and, if that failed, quietly fell back to long polling. One of them, SockJS, became the foundation of Meteor.

Gratis, solo falta un paso

El resto del libro es gratis

Deja tu correo y te mando un enlace para confirmarlo. Después del clic, todos los capítulos se abren aquí, en este dispositivo, durante un año. Cuando salga un libro nuevo, escribiré a esa dirección; responde “basta” a cualquier correo y no vuelvo a escribir.

¿Tienes cuenta INITE? Entra y el libro se abre sin correo.

No se cobra nada por el libro. Si quieres apoyarlo, puedes donar desde cualquier capítulo.

Cómo se guarda la dirección