Ask HN: Any Modern Alternative to JQuery?
I'm an experienced Django developer and I am trying build a modern looking website.
I was trying to complete a React course on Udemy but realised that React (Webpack, Redux, Next, Hooks, etc.) may be an overkill and lead to lot of wasted dev time for my usecase. I have used jQuery previously and the application eventually devolved into spaghetti.
Is there anything better than jQuery but not as complex as react and that integrates well with a backend like Django?
25 comments
[ 1.7 ms ] story [ 68.7 ms ] threadFor example instead of $(".button"), you can do document.querySelector(".button"), and so on.
That said, if you must use a framework and looking for something less complicated than react, look into Vue or Svelte.
Some problems, sure. Every problem? I think that's a stretch. Jquery still has it's applicability and can in some cases lead to simpler code.
- easier AJAX requests (fetch does this)
- selecting nodes using CSS-like selectors (querySelector / querySelectorAll)
Hiding elements too: HTML now has the hidden attribute. Maybe manipulating HTML/CSS classes? (classList has everything)
There are, of course, alternatives to React. Angular, Svelte, and Vue are among the most popular. There are even light weight versions such as Alpine. But it’s hard to make any recommendations without understanding your requirements.
Since you're building such a website, a common option for you may be to use a lightweight framework like Svelte/Sapper as your client. I've been using this for most projects with a Django backend.
I'd consider vanilla JS anyway and switch to a framework if things get too complicated.
edit: one can go a very long way with just HTML/CSS now, and this allows very fast and accessible websites.
https://htmx.org/
htmx allows you to access AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext
htmx is small (~9k min.gz'd), dependency-free, extendable & IE11 compatible
https://htmx.org/docs/#targets
Also, TailwindCSS is complementary imo.
I think one pro React has is its performance advantage over jquery and handled edge cases. There are some others like Vue or Svelte which could be more performant on other cases but I have bias on React because of its ecosystem, e.g. if I want cute icons I know FontAwesome has its own dedicated react component. Cute charts? Airbnb has visx charting components.
$ is easier to type than document.querySelector and it absorbs browser differences.
And why not just install jQuery? What's the big deal?
Where can I find the short aliased library? (If it's not there, I guess it's not a popular idea.)
In the last 5+ years, I have never found myself missing something from jQuery. Is there something that jQuery does marginally better than vanilla JS in 2020?
> What's the big deal?
Sending unnecessary dependencies over the wire without any justification
$("#something").innerHTML = "Hi"; is vanilla JS.
I haven’t tested it but it looks interesting and might be going in the direction you are looking for.
Fetch or one of the wrapper libraries has HTTP covered.
Typescript is great if you want everything to work seamlessly on older browsers while using modern JS.
Yeah it's a lot to learn but once you know it, it's just as efficient as the old "JQuery forests + HTML" and way more maintainable.
I did ASP.NET MVC for years and once I learned React + Angular I never looked back. They work just like the desktop UI libraries of old, which is a good thing.
Django and related "server side" frameworks are functionally obsolete unless you have a very static website that needs perfect SEO (ex blog, news site)
Bottom line: Use javascript without a library.