Ask HN: Best tiny JavaScript framework?
I'm deciding on a Javascript framework to use in building a real time chat application with a tiny footprint. I can't use React, Angular, Ember, or Vue because they are too large. I would build the app in vanilla Javascript, but I fear that it will become more and more difficult to maintain and I will end up reimplementing many already solved problems.
Some of the frameworks that I've seen that are small, fast, and well-liked are Preact, Inferno, Mithril, and Ractive. Does anyone have any experience with these, or even better, thoughts on a comparison between them?
45 comments
[ 5.6 ms ] story [ 125 ms ] threadhttps://gist.github.com/Restuta/cda69e50a853aa64912d
If you do find something smaller, the amount of glue or performance related code you add will probably end up being more than Preact.
[0]: http://monkberry.js.org/
[1]: https://redom.js.org/
You can even precompile your Handlebars templates as an optimization and include a smaller subset of the Handlebars library that is just the runtime without the compiler.
You'd be better using something small and efficient like Vue to get it released and optimise it later if it's successful. Optimising now for extremely small file sizes doesn't sound like a good idea to me in terms of getting it finished.
The reality with side projects is they're much more likely not to be used because they're not finished, not because they're a few KB too big.
"The web sucks if you have a slow connection"
https://news.ycombinator.com/item?id=13601451
https://danluu.com/web-bloat/
A better designed version of Backbone with a small footprint.
When experimenting with substituting a few modules, I've gotten it down to 4.5k gzipped.
It's still quite early on (alpha), but already some folks are using it in production. Plus, it's mostly backwards-compatible with Knockout.
While it might not be an ideal, usable solution for this problem yet, it's definitely moving in the direction of filling exactly this niche (among others).
I adapted it for myself here: https://gitlab.com/heycato/domjs/blob/master/dom.js
That is the funniest thing I've read all day.
Size < 8kb gzipped (includes routing and ajax)
Memrise.com use it for their apps.
Guild Wars 2 uses it for in-game UI.
More here: https://github.com/lhorie/mithril.js/wiki/Who-Uses-Mithril
Check also http://riotjs.com/ 9.73KB (gzip)
http://maquettejs.org https://github.com/nextorigin/gulp-pug-hyperscript
For a small framework, I've been using SpineJS for years. https://github.com/spine/spine/
Example with Maquette:
https://github.com/nextorigin/maquette-mapper
Using focused, quality components has let me upgrade my stack piece by piece over the years while retaining backwards compatibility.
Maybe add Jquery if you want something just above plain JavaScript.
Edit:
Another benefit of Handlebars is that if you ever do decide you need a full framework, you can use Ember and leverage your Handlebars templates.
Then again, maybe I should just put the time in to make a well architecture and maintainable plain vanilla Javascript application. I'm definitely a fan of minimalism.
Like yes, I could build my own routing library, and that is probably fine, and yes I can build my own state management library, and so on, but at a certain point you are just rebuilding a framework from scratch, and oftentimes not very well.
But that's the beauty of using Handlebars. If at a later date you do need a full fledge framework, you can use Ember - that uses a superset of Handlebars.
No template syntax to learn, one function API, 5kb gzipped.
https://news.ycombinator.com/item?id=13816429
Use any tiny View Library like Preact Inferno, etc. and use the Flux Architecture without any other framework, you implement the store by hand or using some immutable lib and use a simple dispatcher. That way you have a maintainable code since Flux is pretty popular and no big framework.
It looks like tiny React and is just 511b gzipped.
Edit Gruntfile.js to do that or try a site like: projects.jga.me/jquery-builder/
You can get sub-20Kb builds with just what you need. I did that recently to inline the core parts ...
One tip, if you use the builder, take a screenshot! The file generated will have a comment block with - in front of omitted modules, e.g. -ajax if you prefer plain old fetch & other useful info. But the screenshot shows exactly what options you set.