Building single-page web applications
with Ruby on Rails

What are single-page apps?

The pursuit of better user experience changes the way we think about browsing the web. As the Internet matures, we abandon the classic approach whereby the user is presented with a handful of URLs which reload the page when clicked; the new approach aims to make the web application work seamlessly. This is achieved by retrieving all the code needed with a single-page load and, subsequently, changing only some elements on the page, depending on the actions taken by the user. Such an approach has a few benefits. It ensures a fine-grained control over the user experience as it eliminates network latencies and disruptions caused by page redraws. It can also save resources like bandwidth and CPU time on the server side.

There are various techniques which allow to retain a single-page during the client-server communication process. On a higher level of abstraction, the main difference between these techniques boils down to the opposition: “thick server architecture vs. thin server architecture” or “fat client vs. thin client”. A “fat client” is able to perform many tasks without accessing the server. In contrast, a thin client, generally, does as little processing as possible and depends on connecting to the server each time user input needs to be processed or validated.

There are certain advantages to making the client thin and delegating all the data processing, such as, for example, rendering appropriate HTML and/or JavaScript, to the server. For instance, it is easier to develop and deploy web applications where almost the entire code runs on the server. The disadvantage of frequent server access is that your thin-client single-page application is as fast as the network connection between the client and the server. So, just as the user experience was affected by page redraws, it is now limited by the request/response scheme. Having taken an action in the system, the user is presented with spinners or flash messages like “work in progress…”, rather than immediate results. Some say that single-page apps could take another step forward and make the interfaces completely non-blocking. The interactions should be resolved instantly, without spinners or “please wait…” messages affecting user experience. And decoupling network requests from the application interface is the only way to escape the “”jail” where “the web application is as fast as the network connection”.

Moving the application logic to the client would not be possible without the help of Javascript.  Fortunately, there are a number of Javascript frameworks that let you pull some business logic from your Ruby on Rails application to the client side. But before I dive into reviewing Javascript frameworks that let you build great single-page applications with Ruby on Rails, I feel obliged to answer an important question:

Pages: 1 2 3 4 5 6