Show HN: Mizu.js – Lightweight HTML templating library for any-side rendering
225 points| lowlighter | 1 year ago |mizu.sh | reply
I'd like to share a fun project I've been working on: mizu.js.
It's a js library that add functional attributes support into your html, designed to be a simple and flexible alternative to fully-fledged web frameworks (such as Vue, React, and Angular), while offering more capabilities than other lightweight options (like Alpine.js and htmx).
As it's written using modern ES features and due to its isomorphic nature, it can be run in both browsers and runtimes (Node, Deno, Bun) without any changes. This makes it ideal for client-side and server-side rendering, as well as static site generation, whichever environment you prefer.
Just include the script in any web page (or backend) to get started. You can template content, bind attributes, add interactivity, handle HTTP interactions, create custom components, and much more — all out of the box, without any configuration, transpilation steps, or builds.
I hope you'll find mizu.js as exciting and useful as I do and I'd love to get your feedback! You can learn more about it at https://mizu.sh!
Online playground: https://mizu.sh/playground Custom builder: https://mizu.sh/build Code coverage: https://mizu.sh/coverage GitHub: https://github.com/lowlighter/mizu
## Motivation ##
Nowadays, setting up a complete environment and installing thousands of packages is often required just to create a simple "Hello World" page. Yet, with the current ECMAScript standard, vanilla JS has never been more powerful. It offers built-in custom HTML components, proxies for changes tracking, weak references for better memory management, and many new data structures and methods.
So why is web development still insanely complex?
mizu.js aims to avoid adding bloat on top of native features, and instead focus on providing convenience helpers. It's basically "glue" around all these native features with added sugar, a recipe for a lightweight yet powerful utility.
All evaluated expressions are interpreted as vanilla JavaScript, and you add your instructions directly into your HTML. So if you know already know about JS/HTML, then you're already 80% know of how to use mizu.js (add an extra 10% if you've used Vue, Alpine.js or htmx in the past as some syntax and concepts are inspired by it), the rest is basically just remembering the directive names. The learning curve is that small.
Also, you may have heard of https://matcha.mizu.sh, a CSS stylesheet to instantly make your web page stylized. Well, it's a great companion to mizu.js. With both of them, you can create MVPs for your projects super fast!
[+] [-] esco27|1 year ago|reply
[+] [-] cleanerbob|1 year ago|reply
[deleted]
[+] [-] spankalee|1 year ago|reply
I'm working on a somewhat similar system called Heximal. It focuses on adding full-fledged templating to the <template> element, and full declarative component definitions to HTML, plus some built-in custom elements like <h-var>, <h-out>, <h-scope>, <h-include>, and <h-fetch> that make HTML more of a declarative programming language.
A big difference from HTMX is that it doesn't rely on magic attributes, but instead adds full data-binding with rich expressions for any attribute or text content, and control flow, to <template>. And component definitions include defining properties, attributes, styles, etc.
These things are being proposed for HTML, so Heximal is somewhat of a polyfill for HTML from the future. Or it's a bit like Tangle or Curvenote.
https://github.com/elematic/heximal/
[+] [-] mdhb|1 year ago|reply
[+] [-] pickpuck|1 year ago|reply
https://github.com/EPA-WG/custom-element
[+] [-] corinroyal|1 year ago|reply
[+] [-] lowlighter|1 year ago|reply
[+] [-] replwoacause|1 year ago|reply
https://data-star.dev
[+] [-] brianzelip|1 year ago|reply
This project is dual-licensed.
You may use this project under the terms of the MIT License for non-commercial projects OR as long as you are sponsoring this project through GitHub sponsors with a monthly minimum donation of 1 (one) dollar using the link below:
You may use this project free of charge under the terms of the GNU Affero v3.Via https://github.com/lowlighter/mizu?tab=readme-ov-file#-licen...
[+] [-] johncoltrane|1 year ago|reply
[+] [-] withinboredom|1 year ago|reply
[+] [-] replwoacause|1 year ago|reply
EDIT: never mind the license killed it for me. Cool innovation but unusable with its AGPLv3 license.
[+] [-] omtinez|1 year ago|reply
I built my own frontend framework for similar reasons: https://github.com/fresho-dev/mancha. It was meant to adress the lack of lightweight solutions that worked both on the frontend and the backend. The main goal was to start with client side rendering and, only if you reach the point where you need it, switch to server side rendering. It also includes a drop in replacement for TailwindCSS except it won't yell at you for doing everything client side.
What I really wanted was a better maintained version of PetiteVue. But that highlights another problem: I simply can't trust anyone in the frontend JavaScript ecosystem, I've been burned too many times. It took a while to get to the point of it being usable, but now I know no one can pull the rug from under me. I use only the most basic APIs possible, only 1-2 third party dependencies, and as little hacks as possible.
It still has a few warts here and there but I hope to be able to call it a 1.0 stable version soon enough.
[+] [-] replwoacause|1 year ago|reply
[+] [-] Vampiero|1 year ago|reply
[+] [-] serial_dev|1 year ago|reply
https://glosbe.com/hu/en/mizujs
[+] [-] lowlighter|1 year ago|reply
But that's also related to another project of mine, matcha (which is a kind of tea) which is a semantic css stylesheet.
Both were designed as a mini-ecosystem, kind like how you would put tea in your water
[+] [-] ender1235|1 year ago|reply
[+] [-] replwoacause|1 year ago|reply
https://www.hibikihtml.com
And kind of like Imba:
https://imba.io
[+] [-] pvg|1 year ago|reply
[+] [-] toastercat|1 year ago|reply
[+] [-] replwoacause|1 year ago|reply
[+] [-] xingwu|1 year ago|reply
[+] [-] tonyhart7|1 year ago|reply
after fast skimming it, I found its gonna be hard to separate concern when build interactive UI
[+] [-] progx|1 year ago|reply
[+] [-] unknown|1 year ago|reply
[deleted]
[+] [-] gavmor|1 year ago|reply
Parsing the playground demo was a fun scavenger hunt! Too fun... it took me several minutes to find `(coins += income)` at the line break. For me, it's difficult to scan for "code" that's in-lined as strings. That <progress/> eval, especially, is a doozy!
> Use this [eval] directive sparingly, prefer alternative directives for better maintainability and security. This directive is intended for edge cases.
Oh, and yet *eval is the heart and soul of the demo? In fact, it looks like the principal action--creating buildings--is performed by... the progress bar? That's low-cohesion and high-coupling if I've ever seen it.
I would want to know: what are the Mizu ways of modularizing code to increase cohesion and decrease coupling?
Anyways, thanks for sharing and congrats on launching.
[+] [-] CharlieDigital|1 year ago|reply
Write a class or function closure similar to Vue composables.
It's not really the framework or library's job of making your code more modular; that's your job by writing good code.
[+] [-] lowlighter|1 year ago|reply
The ESM version is better suited for small dynamic apps as you can handle context in a better way, and define helper functions rather than declaring them in a html attribute. It makes the code more readable too and this how you'd be able to achieve a more cohesive app.
As for the eval, it's true the doc advertise against, but maybe I was a bit too harsh about it. The reasoning behind avoiding it is the same as "eval()" in js. It's kind of a "god mode" (like you could do *eval="this.remove()") and it may mess up your final rendering as some internal reference may not be properly cleared if you do niche stuff. If you know what you're doing there's no particular issue with it
[+] [-] replwoacause|1 year ago|reply
[+] [-] alexchamberlain|1 year ago|reply
[+] [-] wccrawford|1 year ago|reply
[+] [-] benatkin|1 year ago|reply
It means you don’t have to GPL your own code while your project is non-commercial and you aren’t paying for it. If you decided to make your project comercial you could migrate away from it or pay for it. It also seems to have a loophole if you interpret it a certain way and transfer it, because the person agreeing and the person receiving it under the MIT license would be different people.
[+] [-] lowlighter|1 year ago|reply
While I doubt this project will ever reach the popularity of projects such as docker, terraform, mondogb, wordpress, corejs, and many others, I'd like to avoid having issues that they encountered later due to their licensing.
Basically having companies that could afford to contribute and help maintainers but that choose to not do it just for pure greed, while keeping it free for everyone else that continue to make open project or just non-profit/personal use case.
As I'm no legal expert, the intention may not have been very clear in the wording though
[+] [-] arunaugustine|1 year ago|reply
[+] [-] jraph|1 year ago|reply
It takes one "non-commercial" project to release their code and people can use the MIT licensed version without restriction.
The concept of non-commercial itself is shady: what if someone releases something non commercially, and then someone else uses it commercially?
You probably want to get rid of this, it's complex to understand and to apply. You could have:
- an AGPLv3 version that open source projects will be able to use (commercially or not, there are many successful commercial open source projects)
- a custom proprietary license that someone can use only if they pay, and de facto their project cannot be open source
Of course, this also means that your code can't be used by projects that want to be released under the MIT license. People will need to release under the AGPLv3.
[+] [-] simonw|1 year ago|reply
I suggest licensing under both AGPL and an existing, documented source-available license - maybe BUSL? https://en.wikipedia.org/wiki/Business_Source_License
[+] [-] unknown|1 year ago|reply
[deleted]
[+] [-] err4nt|1 year ago|reply
Authors are free to either create any data-* attributes they wish for any purpose, so long as the custom attributes are prefixed with "data-".
Authors are also free to create any (valid) HTML custom element, and to invent custom attributes for those elements.
But this appears to require authors to write invalid HTML.
[+] [-] zamalek|1 year ago|reply
[+] [-] unknown|1 year ago|reply
[deleted]
[+] [-] beders|1 year ago|reply
On adoption things are simple and clean.
Then your product becomes more complicated and your requirements for data handling outgrow what a tool like mizu can offer.
Then you are facing a choice: Redo everything in a more scalable and expensive (as in dev training, qe needs) framework/library or stick with that you have?
Choose carefully.
[+] [-] lowlighter|1 year ago|reply
If you know that your project is going to be small-scaled (a MVP or POC, a blog, a UI for your home lab, a static website, etc.) then mizu and tools alike may be a good choice.
If you know that you eventually want to have thousands of customers, with hundreds of collaborators, then it might indeed be not the best fit. Going with a more "common" framework like the big name React and Vue is probably better.
Web dev nowadays offer a wide range of application, so everyone needs is different so a one-size-fits-all framework/library is almost impossible to achieve in my opinion
[+] [-] jchw|1 year ago|reply
I would guess the only real way out is to always carefully constrain your scope and keep your application as simple as possible. Easier said than done...
[+] [-] spankalee|1 year ago|reply
It's certainly possible to build sufficiently rich data handling and modularization into HTML, and to make seamless integration between HTML and components and JS.
The fact that plain HTML can be extended with custom elements already means that just about any HTML system can be decomposed so that the the most complex things are encapsulated behind components.
[+] [-] unknown|1 year ago|reply
[deleted]
[+] [-] gwbas1c|1 year ago|reply
That's... weird.
I've evaluated front-end frameworks in the past and considered both free (open source and no cost) against commercial. I can't explain why, but the mandatory donation for commercial use just rubs me the wrong way.
(And don't get me wrong, I've published my own basic HTML templating library here: https://www.npmjs.com/package/pogon.html)
Perhaps I can explain it this way: If I'm doing a hobby/learning project, there's no obstacle to using Mizu. But, if I'm a rank-and-file employee, experimenting, setting up the $1 / month donation is actually a huge obstacle. It's not the cost, it's the actual act of handling money. Furthermore, Mizu will need a lot of paying customers for the monthly donations to actually pay for anything substantial.
Personally, I would think more carefully about how to derive income from Mizu.
[+] [-] gavmor|1 year ago|reply
Is there an uncanny valley between free and enterprise--or is that actually a fertile long tail?
[+] [-] unknown|1 year ago|reply
[deleted]