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.

5
  • 2
    Am I wrong or is this just a bad idea (or perhaps a framework being buzzword-compliant)?. Commented Dec 22, 2008 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: github.com/Wolfy87/tarmac - I haven't done much with it recently because I thought I would be the only user. Commented Jul 16, 2013 at 14:44
  • github.com/yuval-a/ZOE Commented Dec 20, 2015 at 9:33
  • Have a look at TodoMVC, which compares (nearly) all available JavaScript frameworks by implementing a simple TODO App. Commented Sep 17, 2016 at 7: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 Commented Dec 9, 2020 at 6:24

30 Answers 30

70

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

Sign up to request clarification or add additional context in comments.

5 Comments

I am SO glad I found Backbone.
I agree, one to check out definitely!
How to use Backbone in MVC way?
@TristanJuricek is there a free alternative to peepcode?
Skip Backbone and go right for Spine. It's got a much more logical MVC implementation.
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

3 Comments

+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.
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...
The MVC part of JMVC is now can.js
21

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

4 Comments

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.
I assume that's why it's small than backbone? Coffeescript code is more compact...
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...
Browser support is IE >= 9 so check that matches the profile of your visitors.
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

5 Comments

Angularjs is THE best so far in late 2013.... I think....
angular is not a micro framework :/
Agree, Angular is not a micro-framework.
yes, also the learning curve is non-proportional it's benefits comparing to other frameworks.
angular is the very opposite of a micro framework. it's a beast.
14

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

I think you will find this sufficient!

3 Comments

That site has a blink tag. o_0
that site doesn't load for me at all
Try again, should work again.
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!)

1 Comment

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.
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>

3 Comments

is ember advantageous to use over backbone in any way.... if the specifications are not so clear at the initial stages..
I do like emberJS, but it is not "micro" it's HUGE because its a flat out framework
Using Ember and microframework in the same sentence shouldn't be allowed.
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.

1 Comment

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 and jQuery.
8

There is the popular Backbone.js

Comments

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.

Comments

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.

1 Comment

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.
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.

1 Comment

I like it for flex. Simple and powerful.
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.

2 Comments

Could you expand, please, on what is MATZ?
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.
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.

1 Comment

How do you see Claypool in relation to Backbone?
2

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

http://jamal-mvc.com/

Comments

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.

Comments

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.

Comments

2

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

Comments

1

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

Comments

1

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

Comments

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.

Comments

1

Just to make the list a little more complete: ActiveJS

Comments

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.

Comments

0

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

Comments

0

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

Comments

0

Another one: MooTools-MVC

Comments

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.

Comments

0

Try this jQuery based javascript MVC framework.

Comments

0

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

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.