6 ms·
My last two projects have completely forgone jQuery for vanilla JS and a minimal Lodash. Widespread support for querySelector, querySelectorAll, getElementById
by overcast 10y ago
My last two projects have completely forgone jQuery for vanilla JS and a minimal Lodash. Widespread support for querySelector, querySelectorAll, getElementById eliminate all of those handy selector functions. The rest you can read below.
http://youmightnotneedjquery.com/ http://youmightnotneedjquery.com/
This also helps you to learn better javascript, rather than relying on a crutch to string together a lot of convoluted sugar syntax.
- Raphmedia 10y agoThe big advantage of jQuery is that everyone and their dog knows it. You can throw a rock in a crowd, hide the guy you hit and he will be able to code on your projects. This comes with the big disadvantage of jQuery, everyone and their dog knows it and dogs are not great coders.
- overcast 10y agoI try to look at it in a more positive light. Browsers are finally catching up to everything the great jQuery library solved. Now we have a standard built in, that we can all use. This should result in lighter weight experiences, especially as we all move towards mobile.
- throwanem 10y agoYep. Knowing how to get the most out of jQuery, in 2016, mostly means knowing when not to use it.
- sotojuan 10y agoAll the people that hate on jQuery in 2016 either forgot or were not there when it came out and provided a unified solution for the mess that were browsers at the time. Its biggest selling point is not as compelling any more.
- retox 10y agoA victim of its own success, but a success that everyone benefits from.
- MrZongle2 10y agoAmen. When jQuery hit the scene, it was the greatest thing since sliced bread. It's ubiquitous for a reason.
- kedean 10y agoYou're looking at it from an overly pessimistic perspective. jQuery didn't solve any new problems, there were tons of libraries that solved the exact same problems in different ways at the time that it came out, like MooTools, Dojo, and Scriptaculous/Prototype. jQuery was not innovative, it didn't save the world from anything. It's biggest selling point was that the code was easy for designers to pick up, eliminating a lot of the need for the designer/developer dichotomy. tldr; jQuery's success was not innovation or unification, it was an easy to pick up syntax. From there it was all inertia.
- pluma 10y ago> hide the guy you hit Did you mean "hire" or where you intentionally trying to make it sound like you're abducting programmers off the street and hiding them in your basement?
- laurent123456 10y agoThis youmightnotneedjquery.com website is nice but I'd be more interested to know what features are available in jQuery but currently missing from vanilla JS. At the moment, I get the feeling that if I start with vanilla JS, at some point I'll need features that only jQuery provide, so I'll either have to reimplement them in my project, or backpedal and add jQuery.
- overcast 10y agoWell technically nothing is missing from vanillas JS, as jQuery is written in JS. I'd be REALLY interested to hear what you're doing that you couldn't do fairly easily without jQuery. Majority of users are doing basically selectors, setting attributes, ajax, etc. All easily done without it.
- imaginology 10y agoOne reason I still use jQuery is because its ajax() API is much nicer than the XMLHttpRequest API. Edit: another reason: slideUp() / slideDown() are very useful and not easy to implement with native code.
- k__ 10y agoTrue, I hope these pains will be gone with fetch.
- imaginology 10y agoThat depends on whether the Promise specification gets cancellations. I like fetch's clean API, but being able to cancel my ajax requests is essential.
- k__ 10y agoEssential? Why?
- recursive 10y agoAjax is the last thing keeping me in jquery.
- rnnr 10y agoare you aware of html5 fetch? It suffices most of the time but again not compete replacement(if you want to get xml for example)
- recursive 10y agoYes, I'm aware of it. Support is not good.
- sotojuan 10y agohttps://github.com/mzabriskie/axios https://github.com/mzabriskie/axios https://github.com/github/fetch https://github.com/github/fetch Among countless others. Please don't bring in all of jQuery if you're just going to use one function from it.
- overcast 10y agoFrom my original link above. http://youmightnotneedjquery.com/ http://youmightnotneedjquery.com/ var request = new XMLHttpRequest(); request.open('GET', '/my/url', true); request.onload = function() { if (request.status >= 200 && request.status < 400) { // Success! var data = JSON.parse(request.responseText); } else { // We reached our target server, but it returned an error } }; request.onerror = function() { // There was a connection error of some sort }; request.send(); OR Even better, you should just use a reactive front end framework. https://vuejs.org/ https://vuejs.org/ combined with https://github.com/vuejs/vue-resource https://github.com/vuejs/vue-resource is currently my fave.
- jukkakoskinen 10y agoYou're mistaken, Vue doesn't provide any XHR helpers. Look into fetch or superagent, if you need an abstraction.
- networked 10y agoI am not yet sure of it myself, but something like Umbrella JS (http://umbrellajs.com/ http://umbrellajs.com/) may be a good compromise between writing vanilla JavaScript and dealing with its pain points and using jQuery.
- mkoryak 10y ago> This also helps you to learn better javascript, rather than relying on a crutch to string together a lot of convoluted sugar syntax. I disagree that jquery's API is convoluted. And what is wrong with sugar syntax? One can argue that most of es7 is sugar syntax, but we are happy to use it since it makes your code more terse while remaining readable
- overcast 10y agoIt's not that their API is convoluted, but generally what is being generated by a developer is. It's easy to fall down the jQuery rabbit hole, and start making messy decisions, by just using every possible thing available. Reminds me a lot of early PHP developers, writing spaghetti code because it's easy to do so. I'm currently in the process of converting some of my OWN 10+ year old PHP to Node, and it's difficult to sift through it all. My experience with reading a lot of jQuery stuff is similar. Easy to pick up, and do a lot of magic, which means easy to make a mess.
- amagumori 10y agoIf anything node is a hugely magnified version of jQuery in that respect. Instead of using 200 different jquery functions to do stuff, you're using 200 different npm libraries to do stuff.
- debaserab2 10y agoYou know, I hear this sentiment very often on HN and I have to wonder who these websites are being developed for. The last two products I've worked at has had an audience that includes individuals who either cannot or will not upgrade their web browser. They are stuck on whatever their IT department froze their browser version to year(s) ago. This could be internet explorer 9 or some ancient version of Firefox or Chrome. The individuals in this circumstance always amount to what some might consider to be a negligible amount of people (Probably less than 2%), however, I've always been unable to construct a good argument for why we should be unwilling to support 2% of our customer base when using a good cross-browser compatible library like jQuery from the start can save the argument from even taking place. I suspect this is more the nature of working on B2B apps than B2C, although I do wonder how many people are actually looking at the browser analytics of their audience when they are so willing to forsake jQuery for "vanilla javascript".
- overcast 10y agoI agree this used to be the case, but even in my very large, stubborn organization, we have finally upgraded to the most recent IE11 release. Because, so much on the web now, just doesn't work without it anymore. A lot of our issues come from the banking industry, where their apps will just straight not work. We've even had a few say you MUST use Chrome. For a BANK to request that is saying something about the landscape of supporting old browsers. The large push by Microsoft to get people's asses in gear is a good thing. The other half of the planet is using Chrome.
- debaserab2 10y agoWhen my analytics still tell me I have customers accessing my site from internet explorer 9 and 10, I'm not sure what else I'm supposed to do. I can tell them to upgrade all I want, that doesn't mean it's going to happen.
- overcast 10y agoWell, that appears to be what the rest of major organizations are doing. Their techs will literally just tell us too bad. Upgrade or use a different browser, and I agree. Progress.