WARNING: This documentation is for an old version of mithril! Please see the current docs for more accurate info.

Mithril

A Javascript Framework for Building Brilliant Applications

Guide Download v0.1.33

Flattr

What is Mithril?

Mithril is a client-side MVC framework - a tool to organize code in a way that is easy to think about and to maintain.

Light-weight

  • Only 5kb gzipped, no dependencies
  • Small API, small learning curve

Robust

  • Safe-by-default templates
  • Hierarchical MVC via components

Fast

  • Virtual DOM diffing and compilable templates
  • Intelligent auto-redrawing system

Sample code

//namespace
var app = {};

//model
app.PageList = function() {
	return m.request({method: "GET", url: "pages.json"});
};

//controller
app.controller = function() {
	var pages = app.PageList();
	return {
		pages: pages,
		rotate: function() {
			pages().push(pages().shift());
		}
	}
};

//view
app.view = function(ctrl) {
	return [
		ctrl.pages().map(function(page) {
			return m("a", {href: page.url}, page.title);
		}),
		m("button", {onclick: ctrl.rotate}, "Rotate links")
	];
};

//initialize
m.module(document.getElementById("example"), app);

Output

Performance

To run the execution time tests below, click on their respective links, run the profiler from your desired browser's developer tools and measure the running time of a page refresh (Lower is better). Read more

Loading

Mithril 0.28ms
jQuery 13.11ms
Backbone 18.54ms
Angular 7.49ms
React 24.99ms

Rendering

Mithril 9.44ms (uncompiled)
jQuery 40.27ms
Backbone 23.05ms
Angular 118.63ms
React 79.65ms

Safety

Mithril templates are safe by default, i.e. you can't unintentionally create security holes.

To run the tests for each framework, click on the respective links. If you see an alert box, ensuring security with that framework is more work for you.

Test Summary

Mithril (pass) ✓
jQuery (fail) ✗
Backbone (fail) ✗
Angular (pass) ✓
React (pass) ✓

Guide

Build a simple application. Learn the ropes

Read Guide

API

Docs and code samples for your reference

Read docs

Learn Mithril

Weekly articles on how to use Mithril to its full potential.

Read articles

Mailing List

Post questions and discuss Mithril related topics.

Go to mailing list

Social Media