search
HomeWeb Front-endJS TutorialSupercharge your HTML with mizu.js!

Looking to build interactive web apps with ultimate flexibility and adaptability?

Check out ? mizu.js ?‍?!

It offers around thirty powerful directives to dynamically render HTML, listen to events, create custom elements, bind and model attributes, handle HTTP requests, render markdown and code, and much much more!

And it works client-side on any modern browser...

Supercharge your HTML with mizu.js!

...but also server-side on your favorite runtime, whether it's Node, Deno, or Bun! You can even use it for static site generation!

Supercharge your HTML with mizu.js!

Why yet another JavaScript templating library?
I get your concern, but hear me out!

Over the years, I've become increasingly frustrated with the need to set up an entire ecosystem just to create simple interactive web pages. You often need a dedicated toolbox, tons of dependencies, transpiling steps, and to learn a new superset of a language. You may even end up spending more time setting up your environment than actually working on your project!

That's why I grew fond of libraries such as Alpine.js and htmx, which require no setup and are easy to use. However, I felt these had some limitations. Since they were mostly designed for client-side usage, it wasn't really possible to use them in server-side rendering contexts (including static generation).

In the meantime, I started writing more and more isomorphic JavaScript (i.e., working both in client and server) and found Deno to be the perfect runtime for it. Deno relies on web standards rather than implementing its own like Node. Because of this, I encountered some compatibility issues, which shouldn't exist, as developers should be free to use whatever that suits them best, whether it's Node, Deno, Bun or the browser.

With all these points in mind, I started working on « 水 » (mizu, the kanji for water in Japanese), a new library that attempt to addresses all the above-mentioned issues.

And today, I'm excited to introduce it to you!


mizu.js integrates directly with your HTML and uses vanilla JavaScript expressions for its expressions. This means you don't need to learn a new language or paradigm to start using it.

<!-- Conditionally render elements -->
<a>Heads!</a><a>
<b>Tails!</b>

<!-- Render list elements dynamically -->
<ul>
  <li value of>
  <li>
</ul>

<!-- Bind attributes and handle events -->
<form :class="{ 'user-form': true }" input:>
  <input type="text" ::value="input">
</form>

<!-- Template text content -->
<span is date></span>
<span>Today is {{ new Date() }}</span>
</a>

In mizu.js, the first character of a directive indicates its purpose:

  • * for general directives
  • @ for event-based directives
  • : for attribute binding directives
    • :: for two-way binding directives (also known as modeling)

You might notice some similarities with the syntax from other frameworks and libraries, which is intentional.

mizu.js is reactive, automatically updating the DOM whenever your data changes (on the client-side).

Rendering rich content

mizu.js also offers some neat directives to easily render rich content such as markdown or code syntax highlighting.

<!-- Conditionally render elements -->
<a>Heads!</a><a>
<b>Tails!</b>

<!-- Render list elements dynamically -->
<ul>
  <li value of>
  <li>
</ul>

<!-- Bind attributes and handle events -->
<form :class="{ 'user-form': true }" input:>
  <input type="text" ::value="input">
</form>

<!-- Template text content -->
<span is date></span>
<span>Today is {{ new Date() }}</span>
</a>

HTTP based directives

mizu.js offers a set of directives inspired by htmx.

These directives are especially useful in server-rendering contexts for importing content, but they can also be used on the client side to perform HTTP requests.

<!-- Automatically generate a table of contents from h1-h6 tags within the selected element -->
<nav section></nav>

<!-- Render markdown content -->
<div>**hello world!**</div>

<!-- Highlight syntax using TypeScript flavor -->
<code>const foo = "bar"</code>

Working with HTML custom elements

While HTML natively supports custom elements, they can be a bit tedious to use.

mizu.js simplifies this process with a more concise syntax for defining and using custom elements in your documents.

<!-- Fetch and display remote content -->
<div></div>
<div></div>

<!-- Make an HTTP POST request on click and show the response -->
<button custom header foo:></button>

Bonus: You can easily reuse your custom elements in other projects by importing them with a HTTP based directive!

<!-- Create a custom element -->
<template>
  <div>
    There is {{ items.length }} items:
    <ul><slot name="items"></slot></ul>
  </div>
</template>

<!-- Use the custom element -->
<my-element>
  <li>foo</li>
  <li>bar</li>
</my-element>

Miscelleanous

I won't cover every available directive here, but there are many more to explore!
Here's a small selection of some interesting ones:

<template></template>

Using mizu.js programmatically

So far, I've shown how to use mizu.js directly in your HTML documents, but you can also use it programmatically for more advanced use cases.

Because mizu.js directives are just plain HTML attributes, the syntax remains the same for both client-side and server-side rendering. This means you can easily switch between rendering environments without ever changing your templates!

<!-- Automatically update the time every second -->
<!-- Perfect for elements where reactivity can't be tracked -->
<time>{{ new Date() }}</time>

<!-- Execute raw code for special cases -->
<div></div>

Generating static sites

You can generate static sites easily

import Mizu from "@mizu/render/server"

export default {
  async fetch() {
    const headers = new Headers({ "Content-Type": "text/html; charset=utf-8" })
    const body = await Mizu.render(`<div></div>`, { context: { foo: "? Yaa, mizu!" } })
    return new Response(body, { headers })
  },
}

Start using mizu.js today!

Want to experiment with mizu.js without installing anything?
Checkout mizu.sh/playground!

Supercharge your HTML with mizu.js! lowlighter / mizu

? mizu.js is a lightweight html templating engine for any side rendering. No build steps, no config, no headaches.

Visit mizu.sh for a comprehensive overview!

Bonus: mizu.js pairs perfectly with matcha.css to make your websites look fantastic!

The above is the detailed content of Supercharge your HTML with mizu.js!. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js Streams with TypeScriptNode.js Streams with TypeScriptApr 30, 2025 am 08:22 AM

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

Python vs. JavaScript: Performance and Efficiency ConsiderationsPython vs. JavaScript: Performance and Efficiency ConsiderationsApr 30, 2025 am 12:08 AM

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

The Origins of JavaScript: Exploring Its Implementation LanguageThe Origins of JavaScript: Exploring Its Implementation LanguageApr 29, 2025 am 12:51 AM

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

Behind the Scenes: What Language Powers JavaScript?Behind the Scenes: What Language Powers JavaScript?Apr 28, 2025 am 12:01 AM

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The Future of Python and JavaScript: Trends and PredictionsThe Future of Python and JavaScript: Trends and PredictionsApr 27, 2025 am 12:21 AM

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Python vs. JavaScript: Development Environments and ToolsPython vs. JavaScript: Development Environments and ToolsApr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.