Model, View….. Coffee!

MVCoffee is a suite of software tools written in CoffeeScript and Ruby that provides a client-side Model View Controller (MVC) framework and cache. It’s designed from the ground up to work closely with (and take advantage of the coolest features of) Ruby on Rails.

Version 1.1.0 is now released!

Source on github:

mvcoffee.js CoffeeScript library

mvcoffee-rails Rails Gem

js-rails-routes command line utility

Code Demos

To get a feel for how MVCoffee does some of the things it does, check out these demos:

The Philosophy and Benefits

Yes, there are a lot of other client-side MVC frameworks out there. Most of them are somewhat one-size-fits-all, in that they don’t have an opinion about the server-side technology used. MVCoffee could potentially be used with any server-side solution, but it is specifically designed to work closely with Ruby on Rails. Its approach is inspired by the Rails way of doing things, and it takes advantage of and enhances many of Rails’ features, like routes, model associations and validations, metaprogramming techniques and Turbolinks.

The guiding philosophy is this. Caching has both benefits and pitfalls. Rails can make server-side caching easier, but ultimately it’s optional. If you can get by without the benefits, you don’t have to worry about it.

The same is not true on the client.

If you think about it, a web page is a cache. It’s a snapshot of some of your data, frozen in time and held onto indefinitely. Unless the user navigates to another page, or unless you do something explicitly to refresh the data should it become stale, you may be displaying out-of-date data to the user. Or worse, you could be allowing the user to interact with out-of-date data!

Like it or not, you face the pitfalls of cached data on the web, so you might as well enjoy the benefits. If you’re dealing with invalidating stale data (and it behooves you to!), you might as well not be reloading data that isn’t stale. Know whether it’s stale or not, and do the right thing accordingly.

Here are some of the things MVCoffee does to help you keep the data on the client fresh while gaining improved performance:

Reference Guides

To learn more, check out the guides: