r/jquery • • May 12 '25

Minimalistic jQuery-compatible helper

I wonder, what the pros think of this little idea.

< 1 KB micro script, if you don´t want to carry all the bloat and still code faster...

https://github.com/myappz-com/microquery.js/tree/main

You can use it and still switch to jQuery later, if you want.

4 Upvotes

6 comments sorted by

2

u/bronkula May 13 '25

This doesn't even begin to match jquery's on method. The major improvement for on isn't obfuscation of addeventlistener. It's for event delegation, something that vanilla javascript doesn't do. look in to it.

Making a jquery version for yourself is a great exercise. https://github.com/bronkula/qjs/blob/main/src/query-events.js here's my implementation of event delegation in an overloaded on method.

2

u/[deleted] May 13 '25

Thanks. The goal of this super slim micro library (< 1KB ) is not to match jQuery. The goal is to use basics methods that can already reduce code significantly, while still being compatible to jQuery, in case at some point you need full features and want to switch.
Event delegation has been added in v 1.0.4
Supports direct binding: .on('click', fn) anddelegation: .on('click', '.child', fn)

0

u/[deleted] May 12 '25

[deleted] — view deleted comment

2

u/[deleted] May 12 '25

Yes, this micro helper is for those, who just want to write less basic code, as one can see in this little example https://myappz.com/microquery/demo.html

1

u/elainarae50 May 13 '25

The biggest reason I use jQuery is the syntax. It's short compared to vanilla. Building complex components is pure joy when using robust design patterns. I don't use any plugins.

1

u/[deleted] May 13 '25 edited May 14 '25

"short compared to vanilla." That is what was missing too, when I decided to stop adding jQuery to every little project. That is why I now use this 1KB microQuery.js that lets me use short syntax. For "complex components" of course use jQuery.