JavaScript frameworks. If you don’t use them you’ve likely heard of them. The most popular of the lot are React, Angular and Vue. There are, of course, many more to choose from. Every year, The State of JavaScript surveys Javascript developers. The result of this survey reveals the current landscape of the JavaScript world. And, every year, I can’t help but feel a little sadness when seeing one of my favourite little frameworks sitting far down the list. Today I’d like to talk about Mithril.js.

What is Mithril.js?

Mithril is a modern client-side JavaScript framework for building Single Page Applications (SPAs). It’s one of the alternatives to the more popular frameworks I mentioned earlier. It has been used by companies like Vimeo and Nike, and open source platforms like Lichess. Even the popular massive multiplayer online role-playing game, Guild Wars 2‘s in-game store was built using Mithril!

By default, Mithril uses Hyperscript, a JavaScript-based representation of HTML markup to create pages and components. However, it’s trivial to implement Babel to transpile JSX to Hyperscript if you’d prefer that instead. It makes it a lot more akin to developing with React, for instance.

Much like React, Mithril makes use of a virtual DOM to draw and re-draw the page as users interact with it. It’s much more efficient recreating vnodes on the render cycle than to modify the DOM directly. Mithril uses a sophisticated and highly optimized virtual DOM diffing algorithm to minimize the amount of DOM updates, ensuring fast updates to the page as you go.

Why use Mithril.js?

By now you’re probably wondering why you would use Mithril over the above-mentioned frameworks. Well, Mithril is tiny. Smaller than 10kb gzipped out of the box. This means that the user can load it much faster than more bloated front-end frameworks. When it comes to websites, speed is a huge factor.

Don’t be fooled by its small size, Mithril also includes everything you need to create meaningful web-applications like XHR, routing and state management out of the box. There are many great tools out there to manage those aspects in SPAs and you might have your favourites, but with Mithril that’s not necessary. As they put it: No extra libraries, no magic.

Despite what they say, in my opinion, it is kinda magic.

What are the drawbacks?

As with any tool, Mithril isn’t perfect. If you’re reading this post, there’s a good chance that you’re a developer. And, as a developer, you’d understand the important relationship that we developers have with Stack Overflow. Herein lies Mithril’s biggest drawback: If you run into problems with Mithril, you’re unlikely to find a solution to your problem on Stack Overflow. It’s just not popular enough.

However, having said that, Mithril’s documentation is pretty good. There’s also an active Gitter community dedicated to Mithril where you can ask questions if you need help. The only downside is that you might actually have to interact with people and that’s not traditionally a developer strong suit, eek!

Final words

If you didn’t know about Mithril.js before, I hope I’ve enticed you to check it out. Although nowadays I’m a React developer, Mithril was my first framework and it holds a dear place in my heart.

Do you like to use a lesser-known framework or tool? Let me know what it is on Twitter. I’m always looking to expand my repertoire and these hidden gems deserve some love too!