Home · Posts
The Next Web Frameworks
March 29, 2012

Modern web apps need a fat client. But moving everything to the client, with the server as a thin API, doesn't usually work in practice. The backend needs business logic to enforce data integrity, that means you need your models server-side as well, and you often end up wanting server-side HTML rendering for one reason or another. That leaves you fighting against having both a fat client and a fat server.

The solution to duplicated code, of course, is shared code. Browsers speak JavaScript. Therefore, one solution is to use JavaScript server-side. This has fueled some of the popularity of Node.js. But JavaScript is weak: unless they had to talk to a web browser, few programmers would choose JavaScript over, say, Python or Ruby. (Those using its event model are one exception.) Of the four testimonials on Node's homepage, one mentions the "end-to-end JavaScript experience", and another says, "Allowing developers to build one code base using one language – that is the nirvana for developers".

Indeed. But what if you could "build one code base using one language", and that language didn't have to be JavaScript? Browsers only speak JavaScript, but that doesn't mean we have to write JavaScript. We just have to write something that gets compiled to JavaScript. That's not simple, but some languages are better better suited for the task than others. If we want a server-side language that's powerful, yet accommodates straightforward compilation to JavaScript (or other targets), Clojure starts looking like a good choice. I say "other targets" because while we're at it, why not programmatically integrate our CSS and HTML as well? That would truly be one code base using one language. Every part of the client — views, routes, the API client — could be compiled from a more powerful and integrated code base.

I'm hardly the first to be thinking along these lines. Nothing's quite there yet, but I'm confident it's the next step in the evolution of web frameworks. For Clojure, Noir, ClojureScript and handlebars-clj might be good components to start with.

Regarding the design of such a framework, we can build on existing tools to help. CoffeeScript and SASS would be great intermediate languages for the compiler to target. And by bundling existing JS client libraries, like jQuery, Backbone, or mustache, we can increase the surface area we're compiling to.