Urgent.News

What's breaking now, across thousands of outlets.

Tech

Mithril.js for Beginners: The Tiny Framework With Routing, XHR, and Components Built In

Mithril.js is a tiny JavaScript framework — under 10 KB gzipped — that somehow includes everything a small app needs: components, routing, and HTTP requests. While other frameworks split these into separate packages, Mithril ships them in one small file. It is fast, pragmatic, and has been quietly powering production apps for a decade. Mithril's core idea is simple: components are objects with a…

Mithril.js is a compact JavaScript framework, under 10 KB after compression, offering all the essentials for a small application: components, routing, and HTTP request handling. Unlike other frameworks that divide these features into distinct packages, Mithril integrates them into a single lightweight file. This framework is recognized for its speed, practicality, and widespread use in production apps for over a decade.

The core concept of Mithril is straightforward: components are objects with a view function that outputs virtual DOM, and the m.redraw() function refreshes the page when the state changes. There is no need for a build step, JSX, or any magic - just functions that return descriptions of the page.

Incorporating routing is effortless with Mithril. The framework's native routing system enables defining paths and corresponding views using m.route(). As an example, the code snippet below sets up a simple application with two routes: '/home' displaying 'Home' and '/about' showing 'About'.

The ease of use extends to small apps, dashboards, and pages where developers seek structure without a build pipeline. Its small size makes it an excellent choice for embedded widgets and performance-sensitive websites. However, the framework does have its limitations. The community surrounding Mithril is relatively small, so you will encounter fewer tutorials, ready-made components, and Stack Overflow answers compared to more popular frameworks like React or Vue.

Additionally, hiring developers with Mithril expertise can be challenging, and large teams often prefer frameworks with a more extensive ecosystem. Despite these factors, for those who prioritize small size, speed, and self-containment, Mithril.js can provide a robust foundation for a successful side project, delivering impressive results from just 10 KB of code.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Jensen Huang Tweets

Jensen Huang, on X yesterday, hours before Nvidia’s quarterly earnings report: Since my departure, I’ve seen an outpouring of calls from NVIDIA’s employees, investors, business partners, and customers…

More from Wednesday 18 November →