HACKER Q&A
📣 omgmajk

What JS framework/library would you use for lightweight frontend work


I am soon starting a project where I am in need of a JavaScript framework to do pretty much only very lightweight frontend work with. I have looked around at things like react, angular, vue, svelte, ember and so on but all of them seem pretty hefty for the purpose. I could use vanilla JS but I am in the mood for testing something new. The other parts of the tech stack are going to be node/express, some css framework like tailwind or bulma and sqlite. Basically to be as "portable" as possible.

Any advice or tips would be greatly appreciated.


  👤 DLA Accepted Answer ✓
+1 for Alpine. So awesome and can do a lot for you without the complexity of full frameworks. And no build pipeline to mess with. I’ve used Alpine with Go templates on multiple projects and have been very happy.

👤 udbhavs
Petite-vue (https://github.com/vuejs/petite-vue) is also an alternative to Alpine. It offers a v-scope property similar to x-data so you do most things within markup without having to jump to JS, and it will be easier to move to regular Vue if you ever need something more feature-complete down the road.

👤 wilsonfiifi
You can give Mithril.js [0] a go. It's lightweight and has a couple additional goodies such as routing and xhr inbuilt. It has very good documentation as well.

You can also enable JSX [1] if you prefer that to hyperscript.

A site with more code examples and up to date [2]

[0] https://mithril.js.org/

[1] https://mithril.js.org/jsx.html

[2] https://mithril-by-examples.js.org/


👤 alserio
You have already excluded svelte, so maybe you need something more plug and play, but it is lightweight, fast and quick to adopt. It works great even for single dynamic components embedded in static html. But it all depends of on what you need js at all. Since nobody have said it yet, don't forget to look at Solid, it's really a njce gem

👤 daltonlp
After trying alpinejs for a small frontend-only project (https://spreadsheettimeline.com), I am absolutely sold.

Good constructs, low complexity space, no compilation required.

Tailwind is also excellent.


👤 montroser
You might look at Alpine.js.

Or, if you're in the mood for something different, you could also consider native WebComponents. That set of APIs has broad browser support, and can be powerful enough as-is for many applications.


👤 austincheney
I prefer to define front end components as schemas using TypeScript interfaces. I reference elements from event handlers as event.target.

All the composition without any luggage or slowness forced on the user.


👤 Andys
I can't offer you advice, but I am wondering, in the use case of "lightweight", what do we think JS is needed for?

Why not go plain HTML? (with the odd little JS snippet for anywhere it is truly needed)


👤 DarthNebo
Bulma CSS & vanillaJS/jQuery should be enough for most cases. Fast enough, instant feedback/updates and lightweight.

You'll be saving yourself a lot of time by not googling version compatibility issues or some obscure package bug of the front-end framework itself.

You only need full blown frameworks when you create an application which multiple teams would be working independently on and preferably using CI-CD as the means of deployment, this is absolutely not needed when you're trying to validate a solution or build a one-off project.


👤 joshxyz
Chechk this benchmark comparing front-end frameworks (includes alpine, react, vuew, svelte, etc) : https://krausest.github.io/js-framework-benchmark/index.html

Maybe try https://github.com/solidjs/solid


👤 timdaub
I started to use htm as a templating language for fastify and express. It's pretty cool as you have familiar JSX-ish syntax in backend templates.

As a next step, I wanna build my own web components and include the tags on the backend. I want to develop frontend apps by controlling them on the backend.

Ficusjs looked interesting.


👤 Graffur
The answer is React, or if by lightweight you mean library size, then use Preact [0] which is 3kB .

[0] https://preactjs.com/guide/v10/differences-to-react


👤 JSdev1
Vanilla JS is best I recommend sticking with that and improving your skills. Everyone thinks they need a framework but Vanilla is powerful if you know what you are doing

👤 dyeje
Stimulus or Alpine for sure.

👤 the__alchemist
What are your project requirements?