Need advice about which tool to choose?Ask the StackShare community!

Mithril

87
79
+ 1
86
Preact

405
286
+ 1
28
Add tool

Mithril vs Preact: What are the differences?

Introduction

In this article, we will compare the key differences between Mithril and Preact, two popular JavaScript libraries for building user interfaces. Both libraries are designed to be lightweight and efficient, but there are some important distinctions that developers should be aware of. Let's dive into the details.

  1. Virtual DOM Implementation: Mithril and Preact utilize different approaches when it comes to handling the virtual DOM. Mithril uses a diffing algorithm that updates only the necessary parts of the DOM, resulting in efficient rendering and better performance. On the other hand, Preact uses a VNode system that aims to provide a similar API to React, making it easier for React users to switch to Preact.

  2. Package Size: When it comes to the file size of the library, Preact has an advantage over Mithril. Preact's core library is remarkably small, with the minified version being around 4KB. This makes it an ideal choice for projects that prioritize size optimization. Mithril, although still lightweight, has a slightly larger file size compared to Preact.

  3. API Similarity to React: If you are familiar with React, you might find Preact to be more straightforward to work with. Preact aims to provide a nearly identical API to React, including components, lifecycle methods, and hooks. This similarity allows React developers to easily migrate to Preact without significant changes to their codebase. However, Mithril has its own API, which may require a learning curve for React developers.

  4. Community and Ecosystem: React has a massive community and a vibrant ecosystem, which makes finding resources, libraries, and solutions much easier. Preact, being built as a React alternative, can tap into this existing ecosystem and benefit from the wide range of available tools and plugins. Mithril, while having a dedicated community, may have a more limited set of resources and plugins compared to Preact.

  5. Plugins and Extensions: Preact and Mithril offer different approaches when it comes to handling plugins and extensions. Preact has a built-in compatibility layer called "preact-compat" that allows it to work with existing React codebases and plugins. Mithril, on the other hand, provides a simpler and more lightweight core with fewer built-in features, relying on external plugins for additional functionality.

  6. Project Popularity: In terms of popularity, React is undoubtedly at the top, followed by Preact and then Mithril. React has gained widespread adoption and has become the industry standard for building user interfaces. Preact, being designed as a lightweight alternative to React, has also gained popularity and has a growing user base. Mithril, while having its own dedicated community, may have a smaller user base compared to React and Preact.

In summary, Mithril and Preact are both lightweight JavaScript libraries for building user interfaces, but they differ in their virtual DOM implementation, package size, API similarity to React, community and ecosystem support, handling of plugins and extensions, and project popularity. It is important to consider these differences when choosing the right library for your project.

Decisions about Mithril and Preact
Damiano Magrini
Chose
PreactPreact
over
ReactReact

Preact offers an API which is extremely similar to React's for less than 10% of its size (and createElement is renamed to h, which makes the overall bundle a lot smaller). Although it is less compatible with other libraries than the latter (and its ecosystem is nowhere as developed), this is generally not a problem as Preact exposes the preact/compat API, which can be used as an alias both for React and ReactDOM and allows for the use of libraries which would otherwise just be compatible with React.

See more
Get Advice from developers at your company using StackShare Enterprise. Sign up for StackShare Enterprise.
Learn More
Pros of Mithril
Pros of Preact
  • 16
    Lightweight
  • 12
    Faster than React
  • 10
    Pure JavaScript
  • 10
    Virtual Dom
  • 8
    Robust
  • 7
    Unopinionated
  • 7
    Works with ES6
  • 6
    Very active development
  • 5
    Intelligent auto-redrawing system
  • 3
    Flux compatible
  • 2
    Small Learning Curve
  • 14
    Lightweight
  • 5
    Drop-in replacement for React
  • 3
    Props/state passed to render
  • 3
    Performance
  • 1
    ES6 class components

Sign up to add or upvote prosMake informed product decisions

Cons of Mithril
Cons of Preact
  • 1
    Virtual Dom
    Be the first to leave a con

    Sign up to add or upvote consMake informed product decisions

    What is Mithril?

    Mithril is around 12kb gzipped thanks to its small, focused, API. It provides a templating engine with a virtual DOM diff implementation for performant rendering, utilities for high-level modelling via functional composition, as well as support for routing and componentization.

    What is Preact?

    Preact is an attempt to recreate the core value proposition of React (or similar libraries like Mithril) using as little code as possible, with first-class support for ES2015. Currently the library is around 3kb (minified & gzipped).

    Need advice about which tool to choose?Ask the StackShare community!

    What companies use Mithril?
    What companies use Preact?
    See which teams inside your own company are using Mithril or Preact.
    Sign up for StackShare EnterpriseLearn More

    Sign up to get full access to all the companiesMake informed product decisions

    What tools integrate with Mithril?
    What tools integrate with Preact?

    Sign up to get full access to all the tool integrationsMake informed product decisions

    Blog Posts

    JavaScriptGitHubReact+12
    5
    4131
    What are some alternatives to Mithril and Preact?
    React
    Lots of people use React as the V in MVC. Since React makes no assumptions about the rest of your technology stack, it's easy to try it out on a small feature in an existing project.
    Svelte
    If you've ever built a JavaScript application, the chances are you've encountered – or at least heard of – frameworks like React, Angular, Vue and Ractive. Like Svelte, these tools all share a goal of making it easy to build slick interactive user interfaces. Rather than interpreting your application code at run time, your app is converted into ideal JavaScript at build time. That means you don't pay the performance cost of the framework's abstractions, or incur a penalty when your app first loads.
    AngularJS
    AngularJS lets you write client-side web applications as if you had a smarter browser. It lets you use good old HTML (or HAML, Jade and friends!) as your template language and lets you extend HTML’s syntax to express your application’s components clearly and succinctly. It automatically synchronizes data from your UI (view) with your JavaScript objects (model) through 2-way data binding.
    Vue.js
    It is a library for building interactive web interfaces. It provides data-reactive components with a simple and flexible API.
    Backbone.js
    Backbone supplies structure to JavaScript-heavy applications by providing models key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing application over a RESTful JSON interface.
    See all alternatives