134

Are there any client-side JavaScript MVC (micro-)frameworks?

I have a rather complicated HTML form, and it would benefit from the MVC pattern.

I imagine a good solution would provide the following:

  • Model and View update the Controller when values change (Observer pattern)
  • Populate the model from the form data when the page loads
  • Populate the form from the model when the model changes

Ajax, comet, JSONP and all that jazz are serious overkill.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nicholaides
  • 19,211
  • 12
  • 66
  • 82
  • 2
    Am I wrong or is this just a bad idea (or perhaps a framework being buzzword-compliant)?. –  Dec 22 '08 at 22:14
  • 2
    I started working on something a little while ago because I had the same feeling as you. It's as minimal as it gets, AMD and as unopinionated as I could get it. That means no jQuery etc. I know this has been closed now, but I think this *might* be the kind of thing you were looking for: https://github.com/Wolfy87/tarmac - I haven't done much with it recently because I thought I would be the only user. – Olical Jul 16 '13 at 14:44
  • https://github.com/yuval-a/ZOE – Yuval A. Dec 20 '15 at 09:33
  • Have a look at [TodoMVC](http://todomvc.com/), which compares (nearly) all available JavaScript frameworks by implementing a simple TODO App. – koppor Sep 17 '16 at 07:51
  • Look at stimulusjs - for an existing app with server side generated markup, i found this framework to be minimal, least invasive and to the point. Really fun to work with. But may not satify all your requirements – Sudhir N Dec 09 '20 at 06:24

30 Answers30

70

Backbone is a great light-weight framework. Give it a try: http://backbonejs.org/

Nick
  • 1,417
  • 1
  • 14
  • 21
Martin Drapeau
  • 1,484
  • 15
  • 16
33

JavaScriptMVC is an excellent solution. It's everything is a plugin approach enables you to select only the features you need. As of 2.0, it's based on jQuery.

On progressively enhancing your website, that's left up to the user as JMVC provides just a middle layer for development - it's up to you to make that design choice yourself.

However, JavaScriptMVC is simply the best general purpose JavaScriptMVC library because of its powerful event delegation based controllers.

Event delegation lets you escape having to attach event handlers, and simply create rules for your page.

Finally, JMVC is much more than a MVC architecture. It has all parts of the development cycle covered with:

  • Code Generators
  • Selenium and Env.js integrated testing
  • Documentation Engine
  • Automatic Concat+Compress
  • Error detection and reporting
Kevin
  • 6,539
  • 5
  • 44
  • 54
Justin Meyer
  • 1,677
  • 13
  • 15
  • 1
    +1 for JavascriptMVC - I've used it for a few apps now, and it's pretty nice. Skip the code generation examples on the website. I'd imagine those are only there to pacify the Rails fanboys. :) Start with the basic JQueryMX object model, and create a controller. – Chris Jaynes Aug 31 '11 at 02:41
  • 1
    Since I made this comment, I've switched to using Require and Spine. Ultimately they are smaller, more elegant, and less 'Enterprisey' than JMVC. JMVC was nice for our team of Java developers to make the adjustment to JS, but it just doesn't hold up once you start to understand JS better... – Chris Jaynes May 19 '12 at 05:24
  • The MVC part of JMVC is now [can.js](http://canjs.com/) – PHearst Apr 19 '14 at 11:36
21

Spine has an API similar to Backbone but it's a lot smaller. It features prototypal inheritance.

koppor
  • 19,079
  • 15
  • 119
  • 161
Kolja
  • 2,667
  • 1
  • 30
  • 29
  • 2
    It's also written in CoffeeScript and uses CoffeeScript's style of classes — not that that's a huge win, but it's kinda nice. – a paid nerd Nov 11 '11 at 21:53
  • 1
    I assume that's why it's small than backbone? Coffeescript code is more compact... – Brenden Jan 20 '12 at 01:43
  • I love Spine. Use it with RequireJS for pure awesomeness. Don't let the fact that it's CoffeeScript scare you off either, it works fine with normal JS, too... – Chris Jaynes May 19 '12 at 05:26
  • Browser support is IE >= 9 so check that matches the profile of your visitors. – Richard Dec 22 '14 at 17:10
20

AngularJS works well together with jQuery and will help you a lot with MVC structure and strict separation of concerns.

Full testing environment and Dependency Injection included...

Check it out at http://angularjs.org

Vojta
  • 23,061
  • 5
  • 49
  • 46
14

Indeed there is: http://www.javascriptmvc.com/

I think you will find this sufficient!

Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
14

I think this one looks like something you should check out: http://knockoutjs.com/

(As a silverlight / wpf programmer this was the library that made me finally start learning javascript. It is based on the Model-View-View-Model (MVVM) pattern, as for me right now seems like a good choise!)

Larsi
  • 4,654
  • 7
  • 46
  • 75
  • As a silverlight / wpf programmer I evaluated knockout, backbone, and a couple others. At the end of the day I switched to Angular. It has bindings and MUCH more. – jonperl Apr 11 '12 at 23:47
8

There is the popular Backbone.js

koppor
  • 19,079
  • 15
  • 119
  • 161
Drew LeSueur
  • 19,185
  • 29
  • 89
  • 106
8

Ember.js

These are the three features that make Ember a joy to use:

  1. Bindings
  2. Computed properties
  3. Auto-updating templates

Bindings

Use bindings to keep properties between two different objects in sync. You just declare a binding once, and Ember will make sure changes get propagated in either direction.

Here's how you create a binding between two objects:

MyApp.president = Ember.Object.create({
  name: "Barack Obama"
});

MyApp.country = Ember.Object.create({
  // Ending a property with 'Binding' tells Ember to
  // create a binding to the presidentName property.
  presidentNameBinding: 'MyApp.president.name'
});

MyApp.country.get('presidentName');
// "Barack Obama"

Bindings allow you to architect your application using the MVC (Model-View-Controller) pattern, then rest easy knowing that data will always flow correctly from layer to layer.

Computed Properties

Computed properties allow you to treat a function like a property. Computed properties are useful because they can work with bindings, just like any other property.

Auto-updating Templates

Ember uses Handlebars, a semantic templating library. To take data from your JavaScript application and put it into the DOM, create a tag and put it into your HTML, wherever you'd like the value to appear:

<script type="text/x-handlebars">
  The President of the United States is {{MyApp.president.fullName}}.
</script>
Community
  • 1
  • 1
Sam Hasler
  • 12,344
  • 10
  • 72
  • 106
  • 2
    is ember advantageous to use over backbone in any way.... if the specifications are not so clear at the initial stages.. – Bijendra Nov 16 '12 at 11:56
  • 4
    I do like emberJS, but it is not **"micro"** it's **HUGE** because its a flat out framework – iConnor Feb 10 '14 at 16:07
  • 1
    Using Ember and microframework in the same sentence shouldn't be allowed. – tdc Nov 02 '15 at 16:49
8

Stapes.js

Full disclosure: i'm the author of this library :)

If you're looking for something really tiny (1.5kb minified / gzipped) have a look, and tell me if you like it.

Husky
  • 5,757
  • 2
  • 46
  • 41
  • Looks great at first sight! I like your focus on prototypal inheritance (no simulated classes, and no confusing `new` operator). What seems unnecessary is yet another `each` and `map`. I already have them in [Underscore.js](http://underscorejs.org/) and [jQuery](http://jquery.com/). – feklee Jul 28 '12 at 12:57
7

If your requirements are really simple, you could write your own simple MVC like Alex Netkachov did.

His examples are built on dojo (Note: they don't work for me on his page because of a missing dojo.js file), but you could follow the pattern in plain Javascript.

system PAUSE
  • 37,082
  • 20
  • 62
  • 59
4

It's probably overkill for what you need, but SproutCore is an MVC framework, and it doesn't look any more heavyweight than JavaScriptMVC or TrimPath's Junction.

Unfortunately, none of these seem to be built on the principle of progressive enhancement.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
system PAUSE
  • 37,082
  • 20
  • 62
  • 59
  • 1
    JavaScriptMVC's core MVC components are about 1k larger than Backbone's gzipped (while have a number more features). And JMVC is fully able to build progressively enhanced apps. You'd just throw away the Model layer. – Justin Meyer Mar 24 '11 at 17:07
3

Please also checkout jquery-claypool.

jquery-claypool is a small, fast, railable mvc framework built on jquery, based on my experience with django, rails, spring etc. Its very light weight and runs on both on the client and in server environments.

it provides a routing framework for clean mvc, category logging, filters (aop), lazy creation of controllers, inversion of control, convention-over-configuration and not much more by design.

it doesn't do anything jquery already does, feels like jquery, and works like a good framework should: simply.

jquery-claypool

Hope you check it out.

koppor
  • 19,079
  • 15
  • 119
  • 161
3

The popular ActionScript MVC framework PureMVC was recently ported to JavaScript. I haven't had a chance to try it out yet, but I am confident it's good.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ricky
  • 5,365
  • 2
  • 32
  • 30
3

UPDATE 2016: Sammy.js seems to be abandoned.

Have a look at Sammy.js

Text from the site:

A small webframework with class.

  • SMALL Sammy's core is only 16K compressed and 5.2K compressed and gzipped
  • MODULAR Sammy is built on a system of plugins and adapters . Only include the code you need. It's also easy to extract your own code into reusable plugins.
  • CLEAN The entire API was designed to be easy to understand and read. Sammy tries to encourage good encapsulation and application design.
  • FUN What's the real point of development if its not enjoyable. Sammy tries to follow the MATZ approach. It is optimized for developer happiness.
Bijan
  • 25,559
  • 8
  • 79
  • 71
  • Could you expand, please, on what is MATZ? – kstep Apr 01 '16 at 13:22
  • 1
    Yukihiro “Matz” Matsumoto, the creator of ruby has often said that he is “trying to make Ruby natural, not simple,” in a way that mirrors life. So software should feel natural to the user. This is meant by MATZ approach. – Bijan Apr 01 '16 at 13:27
2

Jamal is the lightweightest I've seen. It's also based on jQuery (bonus). Have not used.

http://jamal-mvc.com/

KevBurnsJr
  • 4,869
  • 2
  • 25
  • 16
2

If you want to keep things under control and quite simple, you may don't need a framework, but just implement your own mvc pattern. Just check this article: Model-View-Controller (MVC) with JavaScript by Alex Netkachov on 2006.

Batailley
  • 131
  • 1
  • 4
2

Try kitty. It is only 1.4KB and its only dependency is EJS.

2

Here is a list of all open-source JavaScript Frameworks known to mankind.

http://getopensource.info/explore/javascript/framework/

Or only MVC frameworks

http://getopensource.info/explore/javascript/mvc/

Disclosure: I'm the developer of this website.

Vikrant Chaudhary
  • 11,089
  • 10
  • 53
  • 68
1

CorMVC, easy to understand and to start with, jquery based and does not depend on any server technology

epitka
  • 17,275
  • 20
  • 88
  • 141
1

I wouldn't call this a micro-framework, but it sure looks interesting: Cappuccino Web Framework

PEZ
  • 16,821
  • 7
  • 45
  • 66
1

I have developed a very simple Javascript MVC framework called MCV. It does not do exactly what you ask for, but it is easily extensible with helpers. Anyway, it is definitely micro (1,9kb packed).

It works more or less like Jamal, but I decided to roll my own for two reasons:

  • remove the jQuery dependency (although I use it together with jQuery most of the time)
  • making it extensible with helpers. These are analog to CakePHP behaviors, components and helpers.
Andrea
  • 20,253
  • 23
  • 114
  • 183
1

Just to make the list a little more complete: ActiveJS

Bijan
  • 25,559
  • 8
  • 79
  • 71
1

I upvoted the AngularJS (full disclosure, I'm involved in a limited way with the angular dev effort) and am very excited about it. I did a side-by-side comparison taking one feature for an internal project (sorry don't have signoff to share it) and implementing it in both AngularJS and Backbone. It was a great exercise and in the end, I'm very much leaning towards Angular. The core developers are great about answering questions and they've done a really nice job with builtin databinding, unit/e2e testing and documentation. Its still in beta with 1.0 coming out in near future. The beta is very stable.

There is a bit of a paradigm shift, and they use a fairly different approach than most. Integrating your favorite jquery plugins takes a bit of effort but is doable and has been done (angular-contrib on github).

I will say (and this is a problem for most js-centric frameworks), make sure to investigate how to make your content SEO-friendly (if its important to you). Since joining the angular community in June, I've noticed the interest is growing and a number of people are making posts saying that they've looked at Backbone and others but really like what they are seeing in Angular.

Dan Doyon
  • 6,710
  • 2
  • 31
  • 40
0

Can.js has everything you need and weighs in at just 8 KB. It's taken the best bits from JavaScriptMVC and distilled it into one small, yet kickass framework with observers, widgets, binding, the works. It is compatible with major frameworks (jQuery, Dojo Toolkit, MooTools, etc.). Documentation is excellent and authors are responsive. It is definitely worth a look.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Steven Garcia
  • 2,814
  • 2
  • 24
  • 12
0

There was a key-value binding JavaScript framework called "Coherent", which was inspired by Apple's Cocoa Bindings. The framework has been bought by Apple, but there is still an old copy at http://github.com/trek/coherentjs/tree/master.

Steve Harrison
  • 121,227
  • 16
  • 87
  • 72
0

Maverick is a small JavaScript MVC framework — http://maverick.round.ee

Martin Tajur
  • 5,242
  • 1
  • 20
  • 15
0

I'm going to pipe up here too - AFrameJS works with jQuery, MooTools and Prototype.

Shane Tomlinson
  • 3,310
  • 3
  • 19
  • 12
0

Try this jQuery based javascript MVC framework.

Isaac
  • 2,701
  • 4
  • 30
  • 47
Garion
  • 1
  • 1
0

Another one: MooTools-MVC

Alejandro García Iglesias
  • 16,222
  • 11
  • 51
  • 64
0

One more, lightweight and tiny: http://jqnano.oleksiy.pro/

Mathieu Rodic
  • 6,637
  • 2
  • 43
  • 49
Oleksii G.
  • 487
  • 5
  • 20