10 ms·
http://youmightnotneedjquery.com/ http://youmightnotneedjquery.com/
by emirb 10y ago
http://youmightnotneedjquery.com/ http://youmightnotneedjquery.com/
- andybak 10y agoThat page does an excellent job of convincing me to carry on using jQuery. if (el.classList) el.classList.contains(className); else new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className); vs $(el).hasClass(className); <shivers>
- oneeyedpigeon 10y agoI don't think anyone would suggest you write all of the first codeblock every time you want to check a class. You'd put it in a function and call that, much like jquery does. The point is that this site explains how you do it because a) that's probably easier than trawling through the jquery source b) including this polyfill when you know you need it might save you from requiring all the rest of jquery.
- andybak 10y agoIn that case I'd be much more likely to use a minimal jQuery replacement such as umbrella.js mentioned elsewhere here. That's 3k (vs about 28k for jQuery) so counters most of the 'bloat' objections with jQuery. I'm sure it will still irk some some purists on other grounds however.
- edgarvaldes 10y agoYep, the use of RegExp is enough.
- eng_monkey 10y agoA good example of why I will continue using jQuery for the time being.
- j1vms 10y agoYes, but it's always good for us to remember that everything has a cost, and so does jQuery (memory footprint/new dependency/complexity). It's a conscious decision we should make on every project, and yes in most cases it would take 0.5s to make a decision in jQuery's favor. We should do so anyways, since it's good practice. Taking into account the presumed state of Moore's Law and all.
- cyphar 10y agoTo me, all of the JQuery examples are much nicer to read and write. Sure, you can use raw JS, but why copy annoying boilerplate? (I'm not a JS dev, so I don't have a dog in this fight).
- inopinatus 10y agoThe authors of that page seem to be making their suggestions principally for library authors, to avoid an otherwise unnecessary dependency on jquery.
- Cyph0n 10y agoIs that comparison supposed to show that jQuery is bad or what exactly? Because it's clear that jQuery is much more concise in every single case.
- starquake 10y agoThe reason the site exists is explained on the site itself.
- deleted 10y ago[deleted]
- __jack__ 10y ago"super confusing because the examples are rubbish and do nothing to help the site's argument", solid analysis
- inopinatus 10y agoNo. That site is giving helpful alternatives so that library authors can avoid having jquery as a dependency.
- mhd 10y agoI'm surprised that there's no youmightnotneedprintf.com
- jjnoakes 10y agoI'm surprised you are comparing jQuery (a non-trivial additional dependency with reasonable dependency-less alternatives) to printf (a small piece of a dependency you most likely pull in already with).
- mhd 10y agoOne man's trivial is another man's bother. I consider 30k (less than some images or the rather popular fonts) to be quite trivial for most purposes, and if it gives me a nicer syntax for common operations, it's probably worth it. On the other hand, I've seen actual backlash against printf implementations in libs and the bloat they're causing, never mind potential bugs [1]. So there you go. [1]: https://www.fefe.de/dietlibc/FAQ.txt https://www.fefe.de/dietlibc/FAQ.txt
- jjnoakes 10y agoI'm not advocating for or against jQuery or printf. I'm just pointing out that equating the two (in size, utility, or potential gains by avoiding them) doesn't make a lot of sense. jQuery's ratio of size-versus-additional-utility is much larger than printf's, even more so if you consider typical use cases of each. But it isn't even a fair comparison to begin with. How about comparing jQuery to libc. I'd still argue the ratio is in libc's favor, but no one would have written "I'm surprised that there's no youmightnotneedlibc.com".
- mhd 10y agolibc seems much more substantial, maybe we can split the difference and call it "youmightnodneedstdio.com", although that sounds much less pithy. I still wouldn't be so sure about that ratio. The people decrying the printf family of functions are often targeting small statically linked binaries. Where a few kb shaved off might be a bigger chunk than 30kb are for your usual multi-megabyte front page of today's web.
- Shengbo 10y agoI don't think it's a question of necessity, it's just more convenient and usually a lot less code than doing the same thing without it.
- deleted 10y ago[deleted]