5 ms·
... and plenty of developers prefer using its API even when native methods are available. jQuery is great, and it's still a really useful library in some circu
by onion2k 7y ago
... and plenty of developers prefer using its API even when native methods are available.
jQuery is great, and it's still a really useful library in some circumstances such as supporting incredibly old browsers, but if you're adding 30kb of weight to a page because you don't want to learn the fetch API then you really need to rethink how you think about users.
- kroboker 7y agoAgreed. I've seen numerous times developers include jquery just to make a simple request that can be replaced by XMLHttpRequest. Ref: http://youmightnotneedjquery.com http://youmightnotneedjquery.com
- yyyk 7y agoThat site looks more like an secret advert for jQuery than any attempt to remove it. Maybe a comparison using more modern browsers would be more convincing...
- Carpetsmoker 7y agoA friend of mine created a spoof to make exactly this point: https://youmightneedjquery.com/ https://youmightneedjquery.com/
- cm2187 7y agoWhat strikes me with this youmightnotneedjquery is that half of the examples take many more lines of code than a single jquery instruction.
- archie2 7y agoEspecially when it comes to browser support...why would I not use JQuery in those cases? I still use JQuery to this day, but probably because I don't really rely on JS in my applications that much. Unless you're building an "app" from the get-go, it's still my default choice.
- Silhouette 7y agoEven the information on that page is quite dated now, as IE becomes less relevant. As others have said, some of its examples were ironically pretty good adverts for jQuery at the time it was first published. However, you hardly ever need to use an XMLHttpRequest any more, and the native Fetch API is already as simple as jQuery's interface for most day-to-day tasks. The only major browser that doesn't support Fetch is IE, and if you still need to support IE for now, you might be better off with a simple polyfill for the standard Fetch API rather than coding around jQuery. Similarly, there is no need for monstrosities like calling Array.prototype.forEach.call on a NodeList returned by querySelectorAll instead of jQuery's $.each any more. Again, everything except IE supports forEach directly on a NodeList, and if you still need IE support, you can use a simple polyfill. If you need a real array to work with, an ES6 spread operator will build this for you with something like [...document.querySelectorAll('.someClass')] since the NodeList is iterable these days too.
- baxtr 7y agoMaybe jQuery should be simply included in browsers.
- nobleach 7y agoWhat is jQuery though? From the author's standpoint, it was a library built to smooth out the edges of bad browser support. This is a problem that doesn't exist as much these days. If you're looking for a way to select one or more DOM nodes and manipulate or jack content into it/them, browsers already provide an easy way to do that now days. The other abstractions it provides ($.get/$.getJson, $.each) have no reason to exist anymore. What's worse, the entire promise-like ability in jQuery is incorrect. (but has to be maintained for backward compatibility) So we're left with what? The $? One could simply do `const $ = document.querySelectorAll;` and get quite a bit of the functionality (I wouldn't really recommend this as it's not a drop-in replacement) Now if we mean the entire jQuery ecosystem. Please.... NO! Tons of bloated non-performant libraries for things like carousels... when a simple `overflow: scroll` could have worked. It was such a nightmare to deal with on mobile devices!
- goto11 7y agoThere is more to it than "wanting to learn". You can peruse Can I Use https://caniuse.com/#search=fetch https://caniuse.com/#search=fetch to evaluate if the API is widely enough supported to be viable. Then you have to figure out which bugs and incompatibilities exist across browsers. If you look at http://youmightnotneedjquery.com/ http://youmightnotneedjquery.com/ you will notice that the native approach is at best similar to jQuery, but in many cases more cumbersome and verbose. 30kb is completely insignificant. Using jQuery is just easier and less risk.
- davidweatherall 7y agoA fetch polyfill can be added to a project for ~500 bytes[1] vs jQuery which is ~30kB [2] - or if you were to import just the ajax element from jQuery it would be 13kB [3] And by correctly using polyfills only on browsers that don't support native fetch, the majority of your users (chrome/safari/firefox) won't have any extra dependencies by using fetch, whereas jQuery will need to be loaded on every browser that hits your site. [1] https://bundlephobia.com/result?p=unfetch@4.1.0 https://bundlephobia.com/result?p=unfetch@4.1.0 [2] https://bundlephobia.com/result?p=jquery@3.4.1 https://bundlephobia.com/result?p=jquery@3.4.1 [3] https://www.telerik.com/blogs/jquery-using-only-what-you-need https://www.telerik.com/blogs/jquery-using-only-what-you-nee...
- goto11 7y agoJust for comparison, the "favicon" for Hacker News is 7.66 KB. Does the size of jQuery really matter for a typical web site? If you have just a typical size logo, it will dwarf the size of jQuery, never mind if you have some illustrations or photos.
- davidweatherall 7y agoI agree there are often more important performance issues on sites, especially with images, but that doesn't mean we should completely ignore javascript bundle sizes. In modern sites if javascript doesn't load sites then become non functional, e.g. navs don't work, some SPAs won't work at all. Whereas an image or favicon taking a long time to load shouldn't stop the user from being able to functionally view most of the site.
- jasim 7y agoThat might be false economy. Most images in a page would come above 30kb. I've seen 3rd party widgets for chat and support sometimes bundle their own copy of the React framework, not to mention huge chunks of CSS, most of which are unused.
- yazboo 7y agoIf you're putting jQuery in your main application bundle then it has to be parsed and executed before you can do anything. That's not the same as an equivalent sized image which just needs to be decoded and painted. If it's a chat widget hopefully you're loading it separately. I agree that CSS can also be a problem.
- hdfbdtbcdg 7y agoPretty sure serverside rendered html works just fine before JavaScript is parsed and executed..
- iforgotpassword 7y agoTbh, I still prefer a "classic" no-bullshit website that depends on jQuery just because the dev likes it a thousand times over the modern overloaded "just-because" SPA that depends on five dozen Js frameworks that were hip the day that page was created.
- DanielBMarkham 7y agoYes. We've got an entire generation of front-end guys tooled up with awesome-looking IDEs and six hundred npm packages creating sites that need none of that. Each of these packages has dependencies, bugs, security issues, their own roadmaps, and so on. I believe in brutally low overhead websites, but I'd still use JQuery if I had to. It's one of a very few things that just make sense no matter what you're doing, and combined with CDNs and cache reloads, you're highly unlikely to be pulling even that 30k over the wire when you use it. We're going to make a ton of super-cool websites using the new stuff we have. Meanwhile we're also going to make a ton of messes. The cool kids will move on to more tools and gadgets. The second-string bunch will be left struggling to maintain. At some point there'll have to be a huge clean up. Consultants will make lots of money. Many of these consultants will be the people selling us all this crap we don't need right now. I wish this were some outlier story or a case of crotchety cynicism, but tech has been really consistent about repeating this pattern over and over again, sadly. We keep buying and using things based on the way we feel. Then they don't work out, people get frustrated, make an entirely new layer of stuff designed to make us feel good. Meanwhile, about 1-in-100 of these things turn out to be useful over longer periods of time. I'd give that award to JQuery.
- rmilejczz 7y agoThe whole “so many Js frameworks!” thing is ridiculous. The same dominant frameworks have been popular for _years_ now, and while new frameworks do pop up people mostly use these same dominant frameworks, and these dominant frameworks are incredibly _samey_, relying on reactive data concepts, components, and a Fluxlike data store pattern for more complex apps. Going from React to Vue or even to modern Angular is really not a huge context switch anymore. The Js framework ecosystem is incredibly easy to work with in 2019, sorry if I came off a little strong with my rant but that sentiment makes me cringe. It is absurd hyperbole that’s not productive and doesn’t reflect the real state of web development in 2019 in any way. Overall I agree a framework isn’t a requirement for a good web app
- WillPostForFood 7y agoVery few people are replacing JQuery with super lite pure native JS implementations, it is getting replaced other libraries like React which is a wash, at best, for users.
- namanyayg 7y agoSo do you put 'Content Type' and all that other stuff on every fetch call over and over again?
- wolco 7y agothe uglyness of document.Selector is something that never gets discussed. The 30k load once for the entire site is rarely an issue unless you are building super light where you would avoid using an image because you feared that extra few k.
- deleted 7y ago[deleted]