What is it?
If you're like me, you're already asking yourself, "isn't that just AJAX by another name?" While it definitely shares the same basic concept of updating the DOM in situ, there's a couple of important differences.
For starters, where AJAX is a hack to get around some limitations imposed by the HTTP request lifecycle, Hotwire does away with discrete requests entirely through the use of Websockets. Although Websocket is compatible with HTTP, it's treated as a fundamentally different protocol. Naturally, Rails provides a handy framework component in the form of ActionCable to help with setting up and managing Websocket connections. Hotwire is built on top of ActionCable. Rather than conventional HTTP requests, link navigation and form submission events in a Hotwire application will be sent over a Websocket connection, and the generated responses will be returned over the same connection. Unlike HTTP, Websocket is a full duplex protocol, so these request / response cycles can happen fast. Because the connection is persistent, updates can be made even faster still without the overhead of repeated connection / teardown cycles.
Broadcasting and pushing
Another important distinction between Hotwire and AJAX is the ability to push updates, and to do so to multiple clients at a time. Previously, in order to "push" updates to an application, developers would have to use a work around in the form of long polling. Instead of truly pushing updates to the client, the client would be responsible for opening and maintaining connections. With a true, persistent connection, this is no longer necessary. And since every client is managing it's connection via ActionCable, it gains all of the capabilities that ActionCable provides - namely, the ability to subscribe to channels. This is a big deal because this now means that all of the infrastructure for pub-sub based applications is available out of the box. There's no more need to roll your own complicated, one-off solutions for pushing messages to clients or even groups of clients.
All of this is still technically beta software, so temper any excitement with some caution. That said, this seems to be the approach that the Rails team has committed to, so it's reasonable to expect a production release real soon now.
Since Rails is the platform that all of this is debuting on, it's natural to assume that Hotwire is tied to Rails. As it turns out, though, it's not - Hotwire is explicitly designed so that it can be used with any backend. The Rails implementation is simply a "reference implementation." Why should Rails devs have all the fun?
With the release of Hotwire, in many ways, we've come full circle with the development model for interactive web applications. Hotwire is basically a continuation of techniques like RJS that has brought us all the way back to the days of AJAX. This time, though, it's a well factored component instead of an ad-hoc technique, and the addition of streaming updates is one of those "why didn't I think of that" ideas. In my next article, we'll take a look at a simple example application that uses all of these components.