Mithril vs Qwik: A Comprehensive Comparison
This website is powered by ItGalaxy.io
In the world of frontend development, Mithril and Qwik represent two different generations of web frameworks. While Mithril offers a lightweight, hyperscript-based approach with functional components, Qwik introduces a revolutionary approach focused on resumability and fine-grained reactivity. Let’s explore their differences and use cases.
Table of Contents
- Core Concepts
- Reactivity and State Management
- Templating and Components
- DOM Manipulation
- Event Handling
- Component Composition
- Form Handling
- Lifecycle Management
- Web App Features
- Performance and Bundle Size
- Learning Curve
- Conclusion
Core Concepts
Mithril and Qwik take fundamentally different approaches to building web applications:
- Mithril uses a lightweight hyperscript-based approach with functional components and manual redraw triggers
- Qwik introduces resumability and fine-grained reactivity with automatic lazy loading of JavaScript
Reactivity and State Management
Declare State
Mithril
import m from "mithril";
export default function Name() {
let name = "John";
return {
view: () => m("h1", `Hello ${name}`),
};
}
Qwik
import { component$, useSignal } from "@builder.io/qwik";
export const Name = component$(() => {
const name = useSignal("John");
return <h1>Hello {name.value}</h1>;
});
Update State
Mithril
import m from "mithril";
export default function Name() {
let name = "John";
name = "Jane";
return {
view: () => m("h1", `Hello ${name}`),
};
}
Qwik
import { component$, useTask$, useSignal } from "@builder.io/qwik";
export const Name = component$(() => {
const name = useSignal("John");
useTask$(() => {
name.value = "Jane";
});
return <h1>Hello {name.value}</h1>;
});
Computed State
Mithril
import m from "mithril";
export default function DoubleCount() {
let count = 10;
let doubleCount = count * 2;
return {
view: () => m("div", doubleCount),
};
}
Qwik
import { component$, useSignal, useComputed$ } from "@builder.io/qwik";
export const DoubleCount = component$(() => {
const count = useSignal(10);
const doubleCount = useComputed$(() => count.value * 2);
return <div>{doubleCount.value}</div>;
});
Templating
Minimal Template
Mithril
import m from "mithril";
export default function HelloWorld() {
return {
view: () => m("h1", "Hello World"),
};
}
Qwik
export const HelloWorld = () => {
return <div>Hello World</div>;
};
Styling
Mithril
import "./style.css";
import m from "mithril";
export default function CssStyle() {
return {
view: () =>
m(
"div",
m("h1.title", "I am red"),
m("button", { style: { fontSize: "10rem" } }, "I am a button")
),
};
}
Qwik
import { component$, useStyles$ } from "@builder.io/qwik";
export const App = component$(() => {
useStyles$(`
.title {
color: red;
}
`);
return (
<>
<h1 class="title">I am red</h1>
<button style={{ "font-size": "10rem" }}>I am a button</button>
</>
);
});
Loop
Mithril
import m from "mithril";
export default function Colors() {
const colors = ["red", "green", "blue"];
return {
view: () =>
m(
"ul",
colors.map((color, idx) => m("li", { key: idx }, color))
),
};
}
Qwik
import { component$ } from "@builder.io/qwik";
export const Colors = component$(() => {
const colors = ["red", "green", "blue"];
return (
<ul>
{colors.map((color) => (
<li key={color}>{color}</li>
))}
</ul>
);
});
Event Click
Mithril
import m from "mithril";
export default function Counter() {
let count = 0;
const incrementCount = () => (count = count + 1);
return {
view: () =>
m(
"div",
m("p", `Counter: ${count}`),
m("button", { onclick: incrementCount }, "+1")
),
};
}
Qwik
import { component$, useSignal, $ } from "@builder.io/qwik";
export const Counter = component$(() => {
const count = useSignal(0);
const incrementCount = $(() => {
count.value++;
});
return (
<>
<p>Counter: {count.value}</p>
<button onClick$={incrementCount}>Increment</button>
</>
);
});
DOM Reference
Mithril
import m from "mithril";
export default function InputFocused() {
let value = "";
return {
view: () =>
m("input", {
oncreate: ({ dom }) => dom.focus(),
type: "text",
value,
oninput: (e) => (value = e.target.value),
}),
};
}
Qwik
import { component$, useVisibleTask$, useSignal } from "@builder.io/qwik";
export const InputFocused = component$(() => {
const inputElement = useSignal<HTMLInputElement>();
useVisibleTask$(({ track }) => {
const el = track(inputElement);
el?.focus();
});
return <input type="text" ref={inputElement} />;
});
Conditional
Mithril
import m from "mithril";
const TRAFFIC_LIGHTS = ["red", "orange", "green"];
export default function TrafficLight() {
let lightIndex = 0;
let currentLight = () => TRAFFIC_LIGHTS[lightIndex];
const nextLight = () => (lightIndex + 1) % TRAFFIC_LIGHTS.length;
const instructions = () => {
switch (currentLight()) {
case "red":
return "STOP";
case "orange":
return "SLOW DOWN";
case "green":
return "GO";
}
};
return {
view: () =>
m(
"div",
m("button", { onclick: nextLight }, "Next light"),
m("p", `Light is: ${currentLight()}`),
m("p", "You must ", m("span", instructions()))
),
};
}
Qwik
import { $, component$, useComputed$, useSignal } from "@builder.io/qwik";
export const TRAFFIC_LIGHTS = ["red", "orange", "green"];
export const TrafficLight = component$(() => {
const lightIndex = useSignal(0);
const light = useComputed$(() => TRAFFIC_LIGHTS[lightIndex.value]);
const nextLight = $(() => {
lightIndex.value = (lightIndex.value + 1) % TRAFFIC_LIGHTS.length;
});
return (
<>
<button onClick$={nextLight}>Next light</button>
<p>Light is: {light.value}</p>
<p>
You must {light.value === "red" && <span>STOP</span>}
{light.value === "orange" && <span>SLOW DOWN</span>}
{light.value === "green" && <span>GO</span>}
</p>
</>
);
});
Lifecycle
On Mount
Mithril
import m from "mithril";
export default function PageTitle() {
return {
view: () => m("p", `Page title: ${document.title}`),
};
}
Qwik
import { component$, useVisibleTask$, useStore } from "@builder.io/qwik";
export const App = component$(() => {
const store = useStore({
pageTitle: "",
});
useVisibleTask$(() => {
store.pageTitle = document.title;
});
return <p>Page title: {store.pageTitle}</p>;
});
On Unmount
Mithril
import m from "mithril";
export default function Time() {
let time = new Date().toLocaleTimeString();
const timer = setInterval(() => {
time = new Date().toLocaleTimeString();
m.redraw();
}, 1000);
return {
view: () => m("p", `Current time: ${time}`),
onremove: () => clearInterval(timer),
};
}
Qwik
import { component$, useVisibleTask$, useStore } from "@builder.io/qwik";
export const App = component$(() => {
const store = useStore({
time: new Date().toLocaleTimeString(),
});
useVisibleTask$(({ cleanup }) => {
const timer = setInterval(() => {
store.time = new Date().toLocaleTimeString();
}, 1000);
cleanup(() => clearInterval(timer));
});
return <p>Current time: {store.time}</p>;
});
Component Composition
Props
Mithril
import m from "mithril";
import UserProfile from "./UserProfile.js";
export default function App() {
return {
view: () =>
m(UserProfile, {
name: "john",
age: 20,
favouriteColors: ["green", "blue", "red"],
isAvailable: true,
}),
};
}
Qwik
import { component$ } from "@builder.io/qwik";
import UserProfile from "./UserProfile";
const App = component$(() => {
return (
<UserProfile
name="John"
age={20}
favouriteColors={["green", "blue", "red"]}
isAvailable
/>
);
});
export default App;
Emit to Parent
Mithril
import m from "mithril";
export const AnswerButton = ({ attrs: { onYes, onNo } }) => ({
view: () =>
m(
"div",
m("button", { onclick: onYes }, "YES"),
m("button", { onclick: onNo }, "NO")
),
});
Qwik
import { $, component$, useStore } from "@builder.io/qwik";
import AnswerButton from "./AnswerButton";
const App = component$(() => {
const store = useStore({
isHappy: true,
});
const onAnswerNo = $(() => {
store.isHappy = false;
});
const onAnswerYes = $(() => {
store.isHappy = true;
});
return (
<>
<p>Are you happy?</p>
<AnswerButton onYes$={onAnswerYes} onNo$={onAnswerNo} />
<p style={{ fontSize: 50 }}>{store.isHappy ? "😀" : "😥"}</p>
</>
);
});
export default App;
Slot
Mithril
import m from "mithril";
import { FunnyButton } from "./FunnyButton.jsx";
export default function App() {
return {
view: () => m(FunnyButton, "Click me!"),
};
}
Qwik
import FunnyButton from "./FunnyButton";
export default function App() {
return <FunnyButton>Click me!</FunnyButton>;
}
Slot Fallback
Mithril
import m from "mithril";
import FunnyButton from "./FunnyButton.jsx";
export default function App() {
return {
view: () => m("", m(FunnyButton), m(FunnyButton, "I got Content")),
};
}
Qwik
import FunnyButton from "./FunnyButton";
export default function App() {
return (
<>
<FunnyButton />
<FunnyButton>Click me!</FunnyButton>
</>
);
}
Form Input
Input Text
Mithril
import m from "mithril";
export default function InputHello() {
let text = "Hello world";
const handleChange = ({ target: { value } }) => (text = value);
return {
view: () =>
m("", m("p", text), m("input", { value: text, onchange: handleChange })),
};
}
Qwik
import { component$, useSignal } from "@builder.io/qwik";
const InputHello = component$(() => {
const text = useSignal("");
return (
<>
<p>{text.value}</p>
<input bind:value={text} />
</>
);
});
export default InputHello;
Checkbox
Mithril
import m from "mithril";
export default function IsAvailable() {
let isAvailable = false;
const onUpdate = () => (isAvailable = !isAvailable);
return {
view: () =>
m(
"",
m("input", {
id: "is-available",
type: "checkbox",
checked: isAvailable,
onchange: onUpdate,
}),
m("label", { for: "is-available" }, "Is available")
),
};
}
Qwik
import { component$, useSignal } from "@builder.io/qwik";
const IsAvailable = component$(() => {
const isAvailable = useSignal(false);
return (
<>
<input id="is-available" type="checkbox" bind:checked={isAvailable} />
<label for="is-available">Is available</label>
</>
);
});
export default IsAvailable;
Radio
Mithril
import m from "mithril";
export default function PickPill() {
let picked = "red";
let pills = ["red", "green", "blue"];
const handleChange = ({ target: { value } }) => (picked = value);
return {
view: () =>
m(
"",
m("", `Picked: ${picked}`),
pills.map((pill) =>
m(
".",
m("input", {
id: pill,
checked: picked == pill,
type: "radio",
value: pill,
onchange: handleChange,
}),
m("label", { for: pill }, pill)
)
)
),
};
}
Qwik
import { component$, useSignal } from "@builder.io/qwik";
const PickPill = component$(() => {
const pickedColor = useSignal("red");
return (
<>
<div>Picked: {pickedColor.value}</div>
<input
id="blue-pill"
type="radio"
bind:value={pickedColor}
checked={pickedColor.value === "blue"}
value="blue"
/>
<label for="blue-pill">Blue pill</label>
<input
id="red-pill"
type="radio"
checked={pickedColor.value === "red"}
bind:value={pickedColor}
value="red"
/>
<label for="red-pill">Red pill</label>
</>
);
});
export default PickPill;
Select
Mithril
import m from "mithril";
const colors = [
{ id: 1, text: "red" },
{ id: 2, text: "blue" },
{ id: 3, text: "green" },
{ id: 4, text: "gray", isDisabled: true },
];
export default function ColorSelect() {
let selectedColorId = 2;
const handleSelect = ({ target: { value } }) => (selectedColorId = value);
return {
view: () =>
m(
"select",
{ value: selectedColorId, onchange: handleSelect },
colors.map(({ id, text, isDisabled }) =>
m("option", { key: id, id, disabled: isDisabled, value: id }, text)
)
),
};
}
Qwik
import { component$, useSignal } from "@builder.io/qwik";
export const colors = [
{ id: 1, text: "red" },
{ id: 2, text: "blue" },
{ id: 3, text: "green" },
{ id: 4, text: "gray", isDisabled: true },
];
const ColorSelect = component$(() => {
const selectedColorId = useSignal("2");
return (
<select bind:value={selectedColorId}>
{colors.map((color) => (
<option
key={color.id}
value={color.id}
disabled={color.isDisabled}
selected={`${color.id}` === selectedColorId.value}
>
{color.text}
</option>
))}
</select>
);
});
export default ColorSelect;
Web App Features
Render App
Mithril
<!DOCTYPE html>
<html>
<body>
<div id="app"></div>
<script type="module" src="./main.jsx"></script>
</body>
</html>
Qwik
<!DOCTYPE html>
<html>
<body>
<div id="app"></div>
<script type="module" src="./main.tsx"></script>
</body>
</html>
Fetch Data
Mithril
import m from "mithril";
export default function App() {
let isLoading = false;
let error = null;
let users = [];
async function fetchUsers() {
isLoading = true;
try {
const { results } = await m.request(
"https://randomuser.me/api/?results=3"
);
users = results;
} catch (err) {
error = err;
}
isLoading = false;
}
return {
oninit: fetchUsers,
view() {
if (isLoading) return m("p", "Fetching users...");
if (error) return m("p", "An error occurred while fetching users");
return users.map((user) =>
m(
"li",
{ key: user.login.uuid },
m("img", { src: user.picture.thumbnail, alt: "user" }),
m("p", `${user.name.first} ${user.name.last}`)
)
);
},
};
}
Qwik
import { component$, useResource$, Resource } from "@builder.io/qwik";
type UsersResponse = {
results: {
picture: {
thumbnail: string;
};
name: {
first: string;
last: string;
};
}[];
};
export async function fetchUsers() {
return (await fetch("https://randomuser.me/api/?results=3")).json();
}
export const App = component$(() => {
const data = useResource$<UsersResponse>(fetchUsers);
return (
<Resource
value={data}
onPending={() => <p>Fetching users...</p>}
onRejected={() => <p>An error occurred while fetching users</p>}
onResolved={({ results: users }) => (
<ul>
{users.map((user) => (
<li>
<img src={user.picture.thumbnail} alt="user" />
<p>
{user.name.first} {user.name.last}
</p>
</li>
))}
</ul>
)}
/>
);
});
Performance and Bundle Size
Mithril
- Extremely lightweight (~10KB gzipped)
- Fast virtual DOM diffing
- Built-in routing and XHR
- Minimal API surface
Qwik
- Zero hydration
- Resumable applications
- Fine-grained lazy loading
- Optimal initial page load
- Progressive JavaScript loading
Learning Curve
Mithril
- Simple and straightforward API
- Minimal concepts to learn
- Functional programming approach
- Excellent documentation
Qwik
- New concepts (resumability, lazy loading)
- JSX-like syntax familiar to React developers
- Strong TypeScript support
- Growing documentation and community
Conclusion
Choose Mithril if you:
- Need a minimal, lightweight framework
- Prefer functional programming
- Want built-in routing and XHR
- Value simplicity and performance
- Are building small to medium applications
Choose Qwik if you:
- Need optimal initial page load
- Want zero hydration overhead
- Need progressive JavaScript loading
- Value modern development features
- Are building large, scalable applications
Both frameworks excel in different scenarios:
- Mithril is perfect for lightweight applications that need performance and simplicity
- Qwik shines in large applications that need optimal loading and modern features
The choice between Mithril and Qwik often depends on your specific needs:
- Use Mithril for small to medium projects that need performance and simplicity
- Use Qwik for large applications that need optimal loading and modern development features
Decouvrez plus d’Offres de la plateform ItGalaxy.io :
Découvrez notre gamme complète de services et formations pour accélérer votre carrière.
1. Nous contactez
- Description: Besoin de Formation et des Solutions cloud complètes pour vos applications
- Links:
2. Infra as a Service
- Description: Infrastructure cloud évolutive et sécurisée
- Links:
3. Projets Développeurs
- Description: Découvrez des opportunités passionnantes pour les développeurs
- Links:
4. Développeurs
- Description: Rejoignez notre communauté de développeurs
- Links:
5. Formations Complètes
- Description: Accédez à des formations professionnelles de haute qualité
- Links:
6. Marketplace
- Description: Découvrez notre place de marché de services
- Links:
7. Blogs
- Description: Découvrez nos blogs
- Links:
- comment creer une application mobile ?
- Comment monitorer un site web ?
- Command Checkout in git ?
- Comment git checkout to commit ?
- supprimer une branche git
- dockercoin
- kubernetes c est quoi
- architecture kubernetes
- Installer Gitlab Runner ?
- .gitlab-ci.yml exemples
- CI/CD
- svelte 5 vs solid
- svelte vs lit
- solidjs vs qwik
- alpine vs vue
- Plateform Freelance 2025
- Creation d’un site Web gratuitement
This website is powered by ItGalaxy.io