News for hackers. Stuff that matters.
Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @05:25PM (#17612990)
Removing jQuery is not always a good idea. The best advertisement for jQuery, ironically, is this site: http://youmightnotneedjquery.com/ Look at how simple things are in the left column, and how much more code is needed in the right column.

jQuery has many convenience features such as chaining, for example: item.addClass('selected').siblings().removeClass('selected'); and you don't have to check for nulls after each selection.

Many functions such as closest() and remove() have no equivalents in IE11, and other things such as replaceWith() and before() are not available even in Edge.

For simple sites it is easy enough to remove jQuery, but for more complex javascript applications, especially apps that have a lot of interactivity, removing jQuery will result in more code, or you will end up writing a lot of utility functions thereby creating your own little clone of jQuery.

Re:Removing jQuery from GitHub.com frontend by zackbloom on Wednesday July 25, 2018 @06:17PM (#17613435)
I was one of the developers who made http://youmightnotneedjquery.com. To be fair, we made it in... 2014? There is a lot you can do now which you couldn't do then, just with a browser. A lot of the challenging examples, like animation, you're better off doing with straight CSS.

Ultimately, I haven't actually used jQuery for anything serious in half a decade, and somehow I manage.

Re:Removing jQuery from GitHub.com frontend by sgift on Thursday July 26, 2018 @04:41AM (#17615980)
> Ultimately, I haven't actually used jQuery for anything serious in half a decade, and somehow I manage.

I don't understand that sentiment ... Of course you can "manage" without JQuery. JQuery itself doesn't use JQuery (D'oh) and somehow it can do all these things, so it is possible. The point of JQuery is that I don't have to think about the various (slightly) incompatible implementations of <whatever> in each browser version, but can just use one lib call and be done with it.

JQuery to me is like using a car instead of running to another city. Yes, I could run, but why would I do that ..?

Re:Removing jQuery from GitHub.com frontend by untog on Thursday July 26, 2018 @05:36AM (#17616169)
jQuery to me is like riding a bike with training wheels attached after you've been riding for ten years. You don't need them, but unless you try taking them off you'll never know that.

Browser incompatibilities are basically a non-issue these days for 95% of projects. Animations etc are far better done with CSS than jQuery (particularly when it comes to hardware acceleration). The Fetch API works in every browser. So on and so forth.

I think the OP wasn't suggesting that "managing" without jQuery is difficult. Certainly, I can say that I haven't touched jQuery in years and haven't looked back once. There's nothing I miss.

Re:Removing jQuery from GitHub.com frontend by emsy on Thursday July 26, 2018 @08:37AM (#17616924)
> jQuery to me is like riding a bike with training wheels attached after you've been riding for ten years. You don't need them, but unless you try taking them off you'll never know that.

Why even use wheels when you can reinvent them? I'm not saying there are no reasons to go "bare metal", but satisfying your developer ego is not one of them. Unless you need every inch of performance or control, jQuery (or alternatives) is probably the more reasonable choice.

Re:Removing jQuery from GitHub.com frontend by untog on Thursday July 26, 2018 @09:33AM (#17617308)
Why would it be the reasonable choice when it was created to solve a problem that largely doesn't exist any more?

jQuery wouldn't be created today in anything like its current form. It still lives on largely because of inertia. Using the APIs provided by the browser is in no way reinventing the wheel!

Re:Removing jQuery from GitHub.com frontend by hatchnyc on Thursday July 26, 2018 @12:29PM (#17618705)
There is now a whole generation of FE developers for whom "JavaScript" is synonymous with "JQuery", as evidenced by endless questions on StackOverflow which use the terms interchangeable.
Re:Removing jQuery from GitHub.com frontend by EB66 on Thursday July 26, 2018 @03:24PM (#17620186)
I agree with this sentiment wholeheartedly.

A lot of the commenters here have a very old school view of jQuery. They seem to believe that if you're using jQuery, then you must also be employing manual DOM manipulations, manual state management, etc.

You can implement modern component-ized front-end architecture while still using jQuery. My company built an in-house front-end framework heavily inspired by React and Vue. But instead of abstracting away from the DOM, we've embraced the DOM by utilizing DocumentFragments for highly performant rendering. When our components render, they return regular ole HTMLElements.

The components built using our framework work with or without jQuery. No manual DOM manipulations, one-way data binding, sane state management, templating, child components, state triggers, etc. A lot of us use jQuery simply because we prefer it's compact and expressive syntax.

Re:Removing jQuery from GitHub.com frontend by snarkyturtle on Thursday July 26, 2018 @10:52AM (#17617928)
Because the wheels are proprietary and full of quirks. For instance, $('.foo') returns an array of jquery objects and not HTMLElements that you can act directly upon using the standard API that was made for replacing it.
Re:Removing jQuery from GitHub.com frontend by mariusmg on Thursday July 26, 2018 @07:50AM (#17616686)
>The Fetch API works in every browser

As long as you're using recent versions. The whole point of jQuery is that you can write some code and be sure that it will run correctly in older versions of the browsers.

Re:Removing jQuery from GitHub.com frontend by blauditore on Thursday July 26, 2018 @08:02AM (#17616755)
That's not the whole point of jQuery, it's just one advantage.
Re:Removing jQuery from GitHub.com frontend by snarkyturtle on Thursday July 26, 2018 @10:48AM (#17617895)
Well XMLHttpRequest has support going back to IE7.
Re:Removing jQuery from GitHub.com frontend by badthingfactory on Thursday July 26, 2018 @08:54AM (#17617024)
> The Fetch API works in every browser.

No it doesn't.

Re:Removing jQuery from GitHub.com frontend by dangerface on Thursday July 26, 2018 @05:06AM (#17616075)
> The point of JQuery is that I don't have to think about the various (slightly) incompatible implementations

Sure when jQuery was released in 2006, but browsers have had 12 years to improve their compatibility, and they have. Javascript has also had 12 years to improve and simplify its api, and it has.

Your analogy was perfect for jQuery 2006 but in 2018 its more like buying a car to drive around the city or you can just take an Uber, you don't have to walk anymore.

Re:Removing jQuery from GitHub.com frontend by pjmlp on Thursday July 26, 2018 @08:00AM (#17616742)
Tell that to those enterprise customers holding to IE 11, not allowing Chrome and doing their own timely releases of FF ESR.
Re:Removing jQuery from GitHub.com frontend by GordonS on Thursday July 26, 2018 @08:46AM (#17616978)
Where I work we only just upgraded to IE11 - it was a decent-sized project, involving a lot of people and manhours.

I really wish we'd of just ditched it and moved to Chrome or Firefox :(

Re:Removing jQuery from GitHub.com frontend by Spivak on Thursday July 26, 2018 @09:29PM (#17622799)
So you would have a decent sized project involving lots of people and manhours, but without support from your vendor?
Re:Removing jQuery from GitHub.com frontend by royce on Friday July 27, 2018 @08:41AM (#17625495)
If someone is developing web applications in such a way that they need support from their browser vendor to make them work properly ... they're doing it wrong.
Re:Removing jQuery from GitHub.com frontend by Spivak on Friday July 27, 2018 @03:41PM (#17628674)
I was assuming that the upgrade was more of an IT thing, that all the company computers are now on IE11.
Re:Removing jQuery from GitHub.com frontend by GordonS on Saturday July 28, 2018 @03:39PM (#17634622)
Yes, that's correct.

We have a portfolio of hundreds of applications, and needed to make sure every one worked OK on IE 11 before upgrading from IE 9.

Re:Removing jQuery from GitHub.com frontend by mercer on Thursday July 26, 2018 @11:19AM (#17618133)
Also don't forget mobile browsers. I ran into a strange problem where Samsung's "Internet" didn't support something and could not find any online mention of this fact.

(I wish I could remember what it was. Perhaps an array method).

Re:Removing jQuery from GitHub.com frontend by EnderMB on Thursday July 26, 2018 @04:34AM (#17615955)
Haha, I remember when that site was released, and a few of our developers jumped right on it without actually reading the text - namely the second paragraph.

> If you're developing a library on the other hand, please take a moment to consider if you actually need jQuery as a dependency. Maybe you can include a few lines of utility code, and forgo the requirement. If you're only targeting more modern browsers, you might not need anything more than what the browser ships with.

Back then, you were 100% correct that if you were writing a library that you intend to use in other places, having jQuery as a hard requirement was a bad idea. However, one developer managed to convince their PM's to completely strip out jQuery for an upcoming project, despite the fact that this website was for a major charity that had huge accessibility requirements AND required legacy browser support. The devs on that project learned a ton about vanilla JS, but that project was an absolute disaster.

We did get a solid library out of it, though, and at least that didn't have jQuery as a dependency!

Re:Removing jQuery from GitHub.com frontend by zamber on Friday July 27, 2018 @03:36AM (#17624172)
That's more telling about problematic mechanics in your org than about jQuery itself.

Did that convincing developer have more influence than the rest of the team? Why the PM was involved in implementation minutiae?

From what I've seen people tend to complain about office politics usually when they don't grok them. The not grokking part is often a choice stemming from a conviction that code monkeys > managers because "engineering". Following your example, who then has more influence over technical decisions? (at least in your somewhat disfunctional org?)

Re:Removing jQuery from GitHub.com frontend by EnderMB on Friday July 27, 2018 @04:23AM (#17624393)
I think you're reading into it a bit too heavily.

At that company (small agency), at that particular time, the structure was flat, and this was isolated to a project he was leading. It was raised in a developer meeting, where I said the point was that libraries shouldn't have hard dependencies, not that (in 2014) we should be ditching jQuery and writing vanilla JS, especially on projects that needed legacy browser support. He ignored me, and the project ran over by months and causing the company to make a loss.

Company issues aside, he wasn't the only developer to not RTFM at the time, and the site was shared across the web by people calling for the death of jQuery when it still had a very legitimate use.

Re:Removing jQuery from GitHub.com frontend by thomasfedb on Thursday July 26, 2018 @06:58AM (#17616461)
It is a little irritating when libraries that really shouldn't need jQuery had it as a dep. I don't mind using jQuery, but I'd rather not add it to a project just as a dep.
Re:Removing jQuery from GitHub.com frontend by EnderMB on Thursday July 26, 2018 @08:42AM (#17616955)
Absolutely. In the case of libraries it was absolutely solid advice.

Sadly, a lot of people didn't actually read the site, and they decided that jQuery was evil and shouldn't be used on websites at all.

Re:Removing jQuery from GitHub.com frontend by lewisjoe on Thursday July 26, 2018 @03:41AM (#17615758)
It is not about the possibility. We can achieve anything with native browser's APIs without custom/polyfill layers these days.

Point is:

$('#somediv').removeClass('class-to-be-removed')

is so much better than

document.querySelector("#somediv").className = document.querySelector("#somediv").className.replace(/\class-to-be-removed\b/,'');

Re:Removing jQuery from GitHub.com frontend by masklinn on Thursday July 26, 2018 @03:50AM (#17615796)
Broadly speaking I agree with you, but even IE11 supports classList so the "native" version of your bit is really

    document.getElementById('somediv').classList.remove('class-to-be-removed')
Where the native APIs fall down is that

1. they tend not to be chainable/expression-oriented, you can't just `classList.add('foo').remove('bar').toggle('qux')` because the first two methods return `undefined` and the last one a boolean

2. they don't support set-oriented operations at all, it's a chore of manual iterations

Re:Removing jQuery from GitHub.com frontend by lewisjoe on Thursday July 26, 2018 @05:46AM (#17616218)
Spot on! Those are probably the two most important blunt-sides of native APIs.

The last thing I'd want to see is a codebase going from 40 lines of code to 400 lines, because "hey, we removed jQuery and writing verbose js is the new cool these days"

I'd be happy if there's a jquery like polyfill library for DOM manipulation, but again - why not just custom jQuery builds and sizzle.js instead of re-inventing jQuery?

P.S I'm not sure IE11 supports classList. Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/cla...

Re:Removing jQuery from GitHub.com frontend by masklinn on Thursday July 26, 2018 @07:45AM (#17616651)
> P.S I'm not sure IE11 supports classList. Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/cla....

It provides basic support for classlist, add/remove/toggle exist and work as you'd expect. It does not have complete supports of all bits of the API:

* it doesn't support the second argument to toggle so you have to use a conditional/ternary with add/remove

* it doesn't support passing multiple classes to add/remove

* it doesn't support replace

Re:Removing jQuery from GitHub.com frontend by megous on Thursday July 26, 2018 @06:38AM (#17616391)
IE11 supports classList just fine, except for an argument to toggle. Nothing a little DOMTokenList.prototype change can't fix.

> The last thing I'd want to see is a codebase going from 40 lines of code to 400 lines, because "hey, we removed jQuery and writing verbose js is the new cool these days"

That will only happen if you're incompetent and will not write a few simple helper functions. And probably not even then. Plain DOM API is not that verbose over jQuery. Anyway, just look at what subset of jQuery you use the most and write helpers for that.

Your codebase is already grown by 1000s of lines by using jQuery, so you have quite a head start sizewise if you drop jQuery.

Re:Removing jQuery from GitHub.com frontend by swah on Thursday July 26, 2018 @07:10AM (#17616503)
Another tweet says that removing chaining improved readability...

https://twitter.com/mislav/status/1022409388013834240

But this I'd say is very close to BS territory..

Re:Removing jQuery from GitHub.com frontend by lewisjoe on Thursday July 26, 2018 @07:55AM (#17616719)
It was me, who asked him the question. The answer though isn't satisfactory enough. But again 140 chars is not a good bandwidth for meaningful conversations.

The claim is interesting, but isn't evident enough.

For example, how exactly is

    var element = document.querySelectorAll('.container') 
    element.style.paddingTop = "50px"; 
    element.className = element.className + 'header';
communicating intent better than:

    $('.container').css('padding-top','50').addClass('header')
Re:Removing jQuery from GitHub.com frontend by mercer on Thursday July 26, 2018 @11:24AM (#17618168)
While I do agree in your comparison the second version looks better. At the same time, and this might be a tad too subjective to have much merit, it feels out of place to me.

Instead, I'd use one of the various approaches where I can create a style = {} object and then apply it to the element, which would just fit better within the rest of my javascript.

(which particular approach to use, .cssText, looping through props, or Object.assign, I'm not sure, but my point is any approach that applies a POJO to the node instead of chaining strikes me as more idiomatic. this is not a hill I'd die on though...)

Re:Removing jQuery from GitHub.com frontend by wvenable on Thursday July 26, 2018 @12:07PM (#17618521)
I wonder how many people will notice that your non-jQuery example actually contains a subtle bug.
Re:Removing jQuery from GitHub.com frontend by megous on Thursday July 26, 2018 @06:31AM (#17616368)
Re 2.:

el.querySelectorAll('abc').map(el => ...)...

You may need to copy some methods you'd like to use from Array.prototype to NodeList.prototype though, or use .values() from NodeList everywhere.

Re:Removing jQuery from GitHub.com frontend by masklinn on Thursday July 26, 2018 @07:47AM (#17616665)
That's manual iteration even if it's done via HoF.

Many of jQuery's operations implicitly apply to the entire nodeset regardless of the nodeset's arity.

Re:Removing jQuery from GitHub.com frontend by girvo on Thursday July 26, 2018 @09:48AM (#17617443)
Fair point, though for dynamic and large DOMs I dislike having to go and check whether I’m touching more than one element sometimes — not always though, sometimes it great to just $(‘#bleh’).hide() or what have you! Depends really
Re:Removing jQuery from GitHub.com frontend by masklinn on Thursday July 26, 2018 @11:05AM (#17618022)
That's completely fair, and there are cases where unknowingly selecting and applying complex operations to many nodes is problematic but I think it's a great baseline/default regardless.
Re:Removing jQuery from GitHub.com frontend by mercer on Thursday July 26, 2018 @07:45AM (#17616654)
I usually add: const qs = (selector) => [...document.querySelectorAll(selector)]

so that I can tread my results as a normal array.

Re:Removing jQuery from GitHub.com frontend by pawelk on Thursday July 26, 2018 @05:09AM (#17616087)
Re:Removing jQuery from GitHub.com frontend by lewisjoe on Thursday July 26, 2018 @05:51AM (#17616232)
[Same Link] You can see how poor the browser support is and how big the polyfill is. There's a chance that the polyfill could be bigger than jQuery's removeClass/addClass implementations.
Re:Removing jQuery from GitHub.com frontend by EB66 on Thursday July 26, 2018 @03:34PM (#17620264)
FWIW, a few of the non-jQuery alternatives documented on http://youmightnotneedjquery.com are not equivalent -- they lack some of the functionality that jQuery offers. For example, take a look at $.replaceWith(). If you use $.replaceWith() you can supply an element that has event handlers bound to it and those event handlers will persist after the replacement. But in your alternative code ( el.outerHTML = string; ) you can only pass in a string which of course cannot have event handlers bound to it.
Re:Removing jQuery from GitHub.com frontend by Cthulhu_ on Thursday July 26, 2018 @05:33AM (#17616162)
Is it time to make that site open source and update it, then? Maybe make a version that targets IE 11+ or even discards Edge, that way you can show promises / async/await for just the ajax one, as well as the straight CSS solutions.
Re:Removing jQuery from GitHub.com frontend by realityking on Thursday July 26, 2018 @08:14AM (#17616796)
It is open source. Repo: https://github.com/HubSpot/YouMightNotNeedjQuery

License is MIT.

Unfortunately it seems to be unmaintained.

Re:Removing jQuery from GitHub.com frontend by sbjs on Wednesday July 25, 2018 @06:51PM (#17613650)
I kind of imagine we will one day have a basic poly fill for all the cross platform issues jQuery actually excels at, and then we truly won’t need jQuery since that’s all it’s really good at these days. Things like chaining are an anti pattern and lead to brittle code!
Re:Removing jQuery from GitHub.com frontend by Piskvorrr on Thursday July 26, 2018 @04:55AM (#17616040)
Oh, but we already do have that, over there: https://jquery.com/

What's with the trend "jQ is old, old is bad! We need something that does the same thing, and most importantly is not named jQuery"?

Re:Removing jQuery from GitHub.com frontend by AmericanChopper on Thursday July 26, 2018 @05:15AM (#17616101)
Most DOM manipulation in jQuery goes through jQuery.globalEval, which uses eval(). Meaning if you want to have a CSP, you have to allow unsafe-eval if you need to support jQuery.

CSP is an incredibly useful tool, and it’s close to impossible to use it properly with jQuery.

Re:Removing jQuery from GitHub.com frontend by lmm on Thursday July 26, 2018 @07:27AM (#17616569)
First concrete, legitimate reason I've seen all thread. Is there something fundamental about jQuery's design that forces it to use eval(), or is it possible a new version could avoids that?
Re:Removing jQuery from GitHub.com frontend by AmericanChopper on Thursday July 26, 2018 @07:49AM (#17616681)
Performing evals is a core part of the design. Take a look at the additional notes section on this documentation of the .html method.

http://api.jquery.com/html/

>By design, any jQuery constructor or method that accepts an HTML string — jQuery(), .append(), .after(), etc. — can potentially execute code

This makes jQuery less safe in general, but I think the CSP restrictions this puts in place are probably a greater issue for most people. I’ve been involved in retro-fitting strict CSPs into a few projects, and more than once I’ve been thwarted by very minor use of jQuery in a couple of places.

Re:Removing jQuery from GitHub.com frontend by sbjs on Thursday July 26, 2018 @12:55PM (#17618915)
It's part of the design of the creation of new elements. But that's just one part of jQuery, and a part I would be completely okay with jQuery getting rid of.
Re:Removing jQuery from GitHub.com frontend by emodendroket on Wednesday July 25, 2018 @09:38PM (#17614471)
I don't think I can agree with that idea about chaining.
Re:Removing jQuery from GitHub.com frontend by brailsafe on Wednesday July 25, 2018 @07:58PM (#17614019)
I think those are some broad generalizations that I can't agree with, but Sizzle might be what you're looking for.

https://github.com/jquery/sizzle/wiki

Re:Removing jQuery from GitHub.com frontend by floatboth on Wednesday July 25, 2018 @08:07PM (#17614073)
Sizzle is ancient history at this point. It's the selector engine jQuery used before querySelector became available everywhere.
Re:Removing jQuery from GitHub.com frontend by brailsafe on Thursday July 26, 2018 @04:58AM (#17616049)
Yes, that was the point. What did you think I thought Sizzle was?
Re:Removing jQuery from GitHub.com frontend by floatboth on Thursday July 26, 2018 @07:09AM (#17616500)
"might be what you're looking for", when that person was looking for a "basic poly fill for all the cross platform issues jQuery actually excels at"
Re:Removing jQuery from GitHub.com frontend by brailsafe on Friday July 27, 2018 @12:30AM (#17623446)
Exactly rice. A possible answer to a somewhat ambiguous desire.
Re:Removing jQuery from GitHub.com frontend by jdboyd on Thursday July 26, 2018 @01:43PM (#17619297)
It would be cool if that website was updated then.
Re:Removing jQuery from GitHub.com frontend by Shorel on Wednesday July 25, 2018 @07:05PM (#17613752)
If you only care about writing code, sure.

But in this case (as in many others), code is written just a couple of times per month, and executed millions of times per day in millions of computers all around the world.

Therefore this kind of "low level JavaScript"* optimizations will have a net benefit much, much bigger than the convenience of reading shorter code for a relatively small group of people.

* Quite the contradiction, I know.

Re:Removing jQuery from GitHub.com frontend by andrei_says_ on Wednesday July 25, 2018 @10:47PM (#17614730)
Each computer executes it a limited number of times, with lightning speed. Differences are imperceptible. The cumulative effect you are speaking of is hypothetical.

Writing code which just works on multiple browsers results in faster development and easier to maintain code and frees dev cycles to focus on performance.

Re:Removing jQuery from GitHub.com frontend by bihnkim on Wednesday July 25, 2018 @11:31PM (#17614884)
> frees dev cycles to focus on performance

Perhaps this is the case--jQuery saved them so much time that they've reached a point where they are free to optimize their frontend by removing jQuery.

Re:Removing jQuery from GitHub.com frontend by andrei_says_ on Thursday July 26, 2018 @03:22PM (#17620166)
Maybe these are not the same developers?

I know I may be replacing jquery with stimulus or eventually vuejs but writing 5 lines of jquery code for my MVP is exactly the right balance today.

Re:Removing jQuery from GitHub.com frontend by kthejoker2 on Thursday July 26, 2018 @09:38AM (#17617363)
Knuth would approve. If you don't have a product, what are you optimizing?
Re:Removing jQuery from GitHub.com frontend by Shorel on Thursday July 26, 2018 @11:54AM (#17618430)
> Differences are imperceptible.

That argument sounds very postmodern. The main issue with perception is that it easily tricked and even more, it can be strongly influenced by bias.

The cumulative effect can surely be measured and reasoned about.

It is very different to program for your new startup idea where adding features faster than your competition is more important than anything else in order to grow your user base, compared to improving an established product already being used by millions of people.

Different needs, different approaches.

Re:Removing jQuery from GitHub.com frontend by andrei_says_ on Thursday July 26, 2018 @03:28PM (#17620218)
> The main issue with perception is that it easily tricked and even more, it can be strongly influenced by bias.

I agree that this is an issue, mainly with all kinds of manipulation in politics and product quality/quantity/health impacts but the 5ms vs 2ms execution time of JavaScript is not one of the problems.

I’d focus on humanity gleefully steering itself into a climate collapse and mass ecocide while focusing on all kinds of completely irrelevant bs.

Re:Removing jQuery from GitHub.com frontend by GlitchMr on Thursday July 26, 2018 @04:32AM (#17615945)
Things have changed since then. For example, AJAX now is much simpler to use than it used to be.

    async function printExampleCom() {
        let response = await fetch("https://www.example.com/")
        // NB: Response has other methods like json.
        console.log(await response.text())
    }
    printExampleCom()
You need a polyfill for `Request` for Safari and Internet Explorer (but not Edge), but that's about it.
Re:Removing jQuery from GitHub.com frontend by shams93 on Thursday July 26, 2018 @04:49AM (#17616016)
Yeah actually I stead of so much focus on frameworks it's better to focus on better polyfill implementations. It's only a temporary issue in many cases but the larger web does move slowly and then stardards like web components sometimes take a deacde or more to be fully baked. Wasm based polyfill would enable more browser maker innovation and competition without leading to slow and bloared pages for all but one device.
Re:Removing jQuery from GitHub.com frontend by Spivak on Thursday July 26, 2018 @09:36PM (#17622825)
What's the point of polyfilling a nice API when you could just have a nice API to start with which leverages native functions when present? They don't seem to be philosophically different.

Or stated differently, "jQuery is just a JS polyfill for browsers that don't support native jQuery yet."

Re:Removing jQuery from GitHub.com frontend by Spivak on Thursday July 26, 2018 @09:33PM (#17622817)
Is there really much of a philosophical difference between a polyfill that exposes a common API and emulates when not present and a library that exposes a common API and uses native functionality when present?
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @05:58PM (#17613282)
If you have even medium complexity you're better off using something like React with Babel or Typescript. Much more sane way of event handling than JQuery, and no mucking with HTML by hand.

I agree with JQuery for the most simple sites, but React+transpiler will give you much better compatibility

Re:Removing jQuery from GitHub.com frontend by EB66 on Thursday July 26, 2018 @03:13PM (#17620079)
It sounds like you're saying using jQuery and a modern component-ized front-end framework are mutually exclusive. jQuery and modern front-end components can go together very easily -- albeit not specifically with React and Vue.

Our company built an in-house front-end framework heavily inspired by React and Vue. The components built using the framework work with or without jQuery. No manual DOM manipulations, one-way data binding, sane state management, templating, etc. Many of us prefer to use jQuery because of how compact and expressive the syntax is.

It really surprises me how many people think that jQuery === old school manual DOM manipulations. It definitely doesn't have to be that way.

Re:Removing jQuery from GitHub.com frontend by ergo14 on Wednesday July 25, 2018 @06:20PM (#17613452)
Thing is react is only compatible with react ;-)
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @06:49PM (#17613636)
It's extremely easy to use React in small parts of the page and spread it out over time. It's a couple lines of code to init React in a div and fully supported. You can even communicate between React bits spread across the page.

React also let's you mark areas/divs within its domain as "don't touch this". So in those areas you can use things like that old map widget you love so much, without resorting to iframes

Angular is a huge fail in this regard. Zero support for mixing with "non angular" pages.

Re:Removing jQuery from GitHub.com frontend by EugeneOZ on Thursday July 26, 2018 @03:14AM (#17615641)
All what you describe in this commentary is much more easy to implement with just jQuery. Your logic more looks like "I can do it with React so it means I should and I believe it's the best tool".
Re:Removing jQuery from GitHub.com frontend by girvo on Thursday July 26, 2018 @09:52AM (#17617476)
Until you’ve got some moderately complex state and infrastructure to handle it, where you end up recreating the whole State -> Render loop of React in jQuery. I recently did this. It works, well, and with less bugs than most hacky jQuery DOM modification, but by the end I was pining for any other modern view library that already solved this. Same reason I used to pine for jQuery on some projects.
Re:Removing jQuery from GitHub.com frontend by feverdream on Wednesday July 25, 2018 @07:40PM (#17613920)
Can you elaborate on this? In my limited experience with React, it takes over your whole application, or at least the whole page. How do you mark areas as "don't touch this"?
Re:Removing jQuery from GitHub.com frontend by kroltan on Wednesday July 25, 2018 @08:05PM (#17614060)
I'm not sure on the "don't touch this" part, but in regards to "taking over the application", it certainly doesn't.

React's entry point is the `ReactDOM.render` function, which takes some React elements, and a root node. that root node can be _any_ DOM node (Actually no idea if you can mount React into a inline SVG, but at least any _HTML_ node you certainly can). You can also have multiple `ReactDOM.render` calls, no problem at all.

That initial React element can very well take values and callbacks from your Angular or whatever application.

It can get messy if you nest `ReactDOM.render` within roots that are managed by React, but so would nesting any other UI framework, but the use cases for that are... Exuberantly exotic, to say the least.

Re:Removing jQuery from GitHub.com frontend by mhink on Thursday July 26, 2018 @12:04AM (#17614987)
So, the way to look at it is that you “mount” a React application at a specific part of the DOM. Anything under that point is managed by React components.

Usually, people have a single “mount point” very close to the <body> element, and a single script file whose primary purpose is to call ReactDOM.render to “mount” a React component representing their application at that point.

However, that doesn’t prevent you from having DOM outside that mount point, and it doesn’t prevent you from having code which does other things that don’t have anything to do with the React-managed part of the page. This is a great way to migrate a legacy application to React: you choose one small section of your page to replace with React, and then have the remainder of your page interact with it by 1.) choosing when to call ReactDOM.render again to ask it to update, and 2.) passing in callbacks so the React ”mini-app” can notify the rest of your application when something happens.

You can go the other way, too, although it’s a little less safe. If you have a React component which renders, say, a <div> with no children, you can get a handle to the DOM element itself and interact with it just like you would in a non-React application. The only constraint here is that you have to make sure to clean up e.g. event handlers and release references to those elements if something causes the “owner” React component to unmount. This is how people make wrapper libraries which let you use non-React-based libraries using React components. (I’ve done this in a side project where I had a huge number homogenous DOM elements to work with, and found that managing them myself was much more performant than trying to run them through React’s model.)

Re:Removing jQuery from GitHub.com frontend by disiplus on Thursday July 26, 2018 @03:04AM (#17615583)
i have something like that in one of my projects, there is "inbox" in one of my apps, it is handled with react, and the header, and top menu are outside of react and generated from backend. it works great. the only problem i had is in the developing, the thing that i did is i developed the inbox feature separately and then im copying the dist to my app on compile.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @08:17PM (#17614126)
I haven't had to do so much myself, but the docs have decent info on how to obtain it. https://reactjs.org/docs/integrating-with-other-libraries.ht...
Re:Removing jQuery from GitHub.com frontend by testvox on Wednesday July 25, 2018 @11:37PM (#17614899)
React components mount to any element you want. And everything they do will happen within that element if you are using react conventionally. There is no issue mounting components alongside/inside legacy apps.
Re:Removing jQuery from GitHub.com frontend by FLUX-YOU on Wednesday July 25, 2018 @07:36PM (#17613894)
Angular is a nightmare for complex UI interactions for components that are spread out.

I'm sure experienced people know how to do that properly, but it's really difficult starting out.

Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @08:20PM (#17614135)
Angular's learning curve is the worst I've ever seen. We mostly use it because "Enterprise" but I prefer React when we get permission for that reason.

Too much abstraction, too much magic. It's possible to do just about anything but the docs are sparse enough that you'll be crawling through github PR's and source to figure out how to achieve it sometimes

Re:Removing jQuery from GitHub.com frontend by EugeneOZ on Thursday July 26, 2018 @03:10AM (#17615617)
Angular is an amazing tool for building reusable components and interoperation between them is pretty easy to implement (just use "input/output" handlers). I'm not saying it just to say something opposite, it is really my opinion and it's what I do almost every day.
Re:Removing jQuery from GitHub.com frontend by skeoh on Wednesday July 25, 2018 @08:52PM (#17614283)
Can you elaborate on this? I've integrated React into Angular and Ember projects in the past with no compatibility issues.
Re:Removing jQuery from GitHub.com frontend by ergo14 on Thursday July 26, 2018 @03:11PM (#17620065)
Did the "foreign" elements stamp out react elements or interact with their properties?
Re:Removing jQuery from GitHub.com frontend by skeoh on Sunday July 29, 2018 @04:10AM (#17637064)
I tried not to have multiple frameworks controlling the same DOM elements. It would usually be a React component mounted to a DOM element controlled by a component in another framework.
Re:Removing jQuery from GitHub.com frontend by ergo14 on Wednesday August 01, 2018 @05:55AM (#17661065)
Exactly, that is my problem, if a react component state is altered by "outside world", weird things can happen. So you actually avoided interoperability between solutions.
Re:Removing jQuery from GitHub.com frontend by samueldavid on Wednesday July 25, 2018 @06:24PM (#17613480)
why not Vue?
Re:Removing jQuery from GitHub.com frontend by lucasmullens on Wednesday July 25, 2018 @06:35PM (#17613550)
"something like React" includes Vue.
Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @06:33PM (#17613537)
React is great for rendering (and updating after initial render), but if your app is highly interactive then jQuery makes things easier even when using React for rendering.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @06:45PM (#17613603)
You generally don't mix react and JQuery. The event system + JSX makes jQuery obsolete.

Having worked in complex interactive React/Angular apps as well as ones using JQuery, nobody would ever offer me enough to use JQuery again for this use case. They would have to double my pay for all the pain

Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @07:42PM (#17613943)
Show me a dropdown menu written in React and I'll show you how you can simplify the code significantly by using jQuery in addition to React.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @08:26PM (#17614167)
Development with React is becoming similar to old school event driven desktop apps, thankfully.

If I want a fancy drop-down with accessibility support and theming etc, there's probably 50 different libraries with components I can pull in and use with little fuss. A few lines of code to import and register event listeners.

I was a huge user of jQuery for years, and it also has quite nice UI libraries. But the power of React is the standardized scaffold and lifecycle. I can pull in UI components from almost any library and use them intuitively. Mix and match them on the same page.

Trying to do that in jQuery will quickly drag you to hell.

Re:Removing jQuery from GitHub.com frontend by mariusmg on Thursday July 26, 2018 @08:14AM (#17616794)
>Trying to do that in jQuery will quickly drag you to hell.

Can you elaborate on this please ? I've used lots of libraries with jquery and haven't encountered problems.

Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Thursday July 26, 2018 @09:37AM (#17617358)
Easy to cause it by combining bootstrap components and JQueryUI.

In React you can "scope" a components CSS so none of the styling leaks out

Re:Removing jQuery from GitHub.com frontend by squiggleblaz on Wednesday July 25, 2018 @08:12PM (#17614091)
Can you be more concrete?

If you want some specific code to criticise, there's dozens of dropdown menu widgets available: here's one I found in Google https://github.com/react-component/menu since I've never actually had reason to use a js/html drop down menu widget.

Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @08:21PM (#17614144)
Here's one that uses jQuery. See how much simpler it is? The one you found does have more functionality, but try rewriting the one I found in React without using jQuery. I guarantee it will be much more complicated.

https://github.com/wisercoder/uibuilder/blob/master/SimpleDe...

Re:Removing jQuery from GitHub.com frontend by moretti on Thursday July 26, 2018 @04:31AM (#17615939)
It’s interesting that you find this “simpler”. One of the great advantages of React is that is declarative, it’s easy to understand how a component will render given a set of (props, state). Your example is quite the opposite, the render method violates this principle and each event handler manipulates the DOM using a ref. I’d call this spaghetti-React.
Re:Removing jQuery from GitHub.com frontend by petilon on Thursday July 26, 2018 @11:01AM (#17617997)
Did you miss the fact that this component is interactive? You can't do interactivity declaratively.
Re:Removing jQuery from GitHub.com frontend by moretti on Thursday July 26, 2018 @12:06PM (#17618510)
By declaratively I mean that in React you typically declare how an element should be render given the current (props, [state]).

For example, in vanilla JS, you might have something like:

  const btn = document.createElement('button');
  btn.className = 'btn red';
  btn.onclick = function(event) {
   if (this.classList.contains('red')) {
     this.classList.remove('red');
     this.classList.add('blue');
   } else {
     this.classList.remove('blue');
     this.classList.add('red');
   }
  };

In React instead:

  class Button extends React.Component {
    state = { color: 'red' }
    handleChange = () => {
      const color = this.state.color === 'red' ? 'blue' : 'red';
      this.setState({ color });
    }
    render() {
      return (<div>
        <button 
           className=`btn ${this.state.color}`
           onClick={this.handleChange}>
        </button>
      </div>);
    }
  }
I find it simpler to understand, because render, given its state, describes exactly how the UI should be.
Re:Removing jQuery from GitHub.com frontend by petilon on Saturday August 04, 2018 @08:12AM (#17686544)
This only works for simple cases. Where this breaks down is when you have to inspect the current state of the DOM before deciding what changes to make to it. Example: scroll an element into view if it is not already visible. More examples: drag & drop, interactive resize, etc.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @08:42PM (#17614241)
It's not about how complex the component is. In my experience what matters is how easy it is to use. With React it's easy to build a world in a teacup, and that's mostly a good thing.

For "regular CRUD developers", the vast majority of us, I have zero concern about how big or crazy component code is until it's so huge it impacts page size. I'll use the easiest most feature complete library out there.

React does encapsulation like jQuery never could. I don't care if I have this vanta black box on my page as long as it's easy to mess with and gets the job done

Re:Removing jQuery from GitHub.com frontend by Piskvorrr on Thursday July 26, 2018 @04:58AM (#17616046)
"I have zero concern about how big or crazy component code is until it's so huge it impacts page size." Me and my mobile browser would like to have a few words with you. Not everything that can execute JS is a supercomputer...performance still matters.
Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @08:58PM (#17614318)
You don't care if the code is significantly simpler by using jQuery? I do care. Simpler code is likely to have fewer bugs and is easier to maintain.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @09:22PM (#17614409)
I'm talking about my code specifically. With React I can pull in a massively complex UI component in few lines.

The complexity is shifted to the library that hopefully has thousands of users so is mostly bug free. It simplifies my code at the expense of moving complexity to the shared project. Much preffered since my code will see orders of magnitude less usage than the library itself

Re:Removing jQuery from GitHub.com frontend by j16sdiz on Thursday July 26, 2018 @02:11AM (#17615382)
I care debugibilty and maintainibility. Many projects on github have very short life cycle. If it go unmaintained, how easy can I take over it?
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Thursday July 26, 2018 @09:39AM (#17617374)
I would argue that most websites have a lifetime similar to the components :). For the ones that don't, backwards compatibility on the web is amazing, only thing to worry about is security vulns
Re:Removing jQuery from GitHub.com frontend by Cthulhu_ on Thursday July 26, 2018 @05:40AM (#17616191)
You're correct that simpler code is better, but here's my argument: Large jQuery applications are not simpler, have more bugs, are harder to maintain and have poorer performance than React applications.

jQuery is a DOM manipulation utility library. React is a view rendering library, favoring composition and isolated components.

Re:Removing jQuery from GitHub.com frontend by ben-schaaf on Thursday July 26, 2018 @05:20AM (#17616114)
What do you even need javascript for in a dropdown?
Re:Removing jQuery from GitHub.com frontend by KevanM on Thursday July 26, 2018 @08:01AM (#17616750)
How else are you going to add back in the accessibility you've broken by building it with JavaScript?
Re:Removing jQuery from GitHub.com frontend by petilon on Thursday July 26, 2018 @11:03AM (#17618011)
For filtering as you type?
Re:Removing jQuery from GitHub.com frontend by boubiyeah on Thursday July 26, 2018 @05:39AM (#17616185)
you are seriously mistaken about react then. The whole point of MV libs is that you maintain a model (domain and/or UI) and the UI just redraws itself. JQuery is 100% not needed even for the most complicated React apps.
Re:Removing jQuery from GitHub.com frontend by petilon on Thursday July 26, 2018 @11:12AM (#17618072)
When you have a highly interactive component you're going to need to make a lot of DOM calls to get the current state of the elements and so on. jQuery makes this easy. The benefits of jQuery over making raw DOM calls have been mentioned by many people here already, so I won't repeat them. These benefits of jQuery don't go away even in a React app.
Re:Removing jQuery from GitHub.com frontend by nostalgeek on Wednesday July 25, 2018 @10:40PM (#17614691)
> Many functions such as closest() and remove() have no equivalents in IE11, and other things such as replaceWith() and before() are not available even in Edge.

Many of these can be polyfilled, Going the polyfill route IMHO is a bit better. I use this now : https://polyfill.io .

Re:Removing jQuery from GitHub.com frontend by WorkLifeBalance on Thursday July 26, 2018 @06:28AM (#17616357)
That polyfill relies on a third party which can then effectively gain analytics for your site. They store and keep the referring URLs and user agent combinations.
Re:Removing jQuery from GitHub.com frontend by nostalgeek on Thursday July 26, 2018 @06:32AM (#17616371)
> That polyfill relies on a third party which can then effectively gain analytics for your site. They store and keep the referring URLs and user agent combinations.

That polyfill relies on nothing since you can run your own custom 'polyfill' server, or just download the bundle and serve it from your website. It's completely open source.

https://github.com/Financial-Times/polyfill-service

You're complaining that a public CDN runs some analytics. But they all do that, and this project doesn't mandate that you use their CDN.

Re:Removing jQuery from GitHub.com frontend by Sephr on Wednesday July 25, 2018 @05:28PM (#17613021)
> other things such as replaceWith() and before() are not available even in Edge

Huh? http://youmightnotneedjquery.com/#replace_from_html and http://youmightnotneedjquery.com/#before show solutions that work in IE8+ and Edge.

Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @05:30PM (#17613040)
The replaceWith() function as documented here does not work in IE: https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/r... You may be able to find hacky alternatives, but if you use jQuery you don't have to.
Re:Removing jQuery from GitHub.com frontend by Sephr on Wednesday July 25, 2018 @05:36PM (#17613100)
element.replaceWith(replacement) is just an alias for element.parentNode.replaceChild(element, replacement) with some bonus functionality to convert strings to DOM text nodes. parentNode.replaceChild is not exactly a 'hacky' alternative.

Here it is in the form of a basic polyfill that only supports Elements:

    Element.prototype.replaceWith = function(replacement) {
        if (typeof replacement === "string") {
            replacement = this.ownerDocument.createTextNode(replacement);
        }
        this.parentNode.replaceChild(this, replacement);
    }
Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @05:40PM (#17613142)
Is that just as readable? Is the intent just as clear? Is the improved readability of the jQuery version worth the extra 80kb download to you?

EDIT: Regarding the polyfill, now you are beginning to write your own little jQuery clone.

Re:Removing jQuery from GitHub.com frontend by Sephr on Wednesday July 25, 2018 @05:44PM (#17613176)
GitHub says they are using polyfills instead of jQuery as well. The point is to not have to rely on external frameworks.
Re:Removing jQuery from GitHub.com frontend by balfirevic on Wednesday July 25, 2018 @06:16PM (#17613419)
> The point is to not have to rely on external frameworks.

Why is that a worthwhile goal?

Re:Removing jQuery from GitHub.com frontend by mschuster91 on Wednesday July 25, 2018 @06:23PM (#17613470)
To reduce attack surface as well as maintenance burden for compatibility whenever something breaks during an upgrade.

A polyfill is something that's not needed at all in modern browsers and thus can be considered pretty much final. jQuery is actually surprisingly stable compared to Angular/React/npm/rest-of-the-hipster-crap, but it has had its fair share of incompatibilities too.

Re:Removing jQuery from GitHub.com frontend by Spivak on Thursday July 26, 2018 @09:38PM (#17622832)
Is a set of polyfills philosophically different than a framework?
Re:Removing jQuery from GitHub.com frontend by nwienert on Wednesday July 25, 2018 @05:34PM (#17613070)
To be fair, that site doesn't use `fetch` on the ES side which bloats all the starting examples.

Further, there are many better animation libraries.

And finally if you use any view framework you have very little need to be traversing the DOM.

Re:Removing jQuery from GitHub.com frontend by Ajedi32 on Wednesday July 25, 2018 @09:42PM (#17614490)
For comparison, here's the first example, but using fetch:

    fetch('/my/url').then((r) => r.json()).then((data) => {

    })
And as an added bonus, fetch uses promises, so in an async function that's just:

    let data = await fetch('/my/url').then((r) => r.json())
Re:Removing jQuery from GitHub.com frontend by Cthulhu_ on Thursday July 26, 2018 @05:41AM (#17616201)
I'm not a fan of mixing await and .then myself;

    let data = await (await fetch('/my/url')).json();
That's a one-liner, but you can split the request and json data as well (and you usually want to anyway because of error handling).
Re:Removing jQuery from GitHub.com frontend by aloisdg on Thursday July 26, 2018 @02:31AM (#17615450)
You can write `(r)` like this `r`. Remove clutter. You don't write `let i = (0)`
Re:Removing jQuery from GitHub.com frontend by klodolph on Thursday July 26, 2018 @07:54AM (#17616710)
That’s not a good analogy at all, the () is there in arrow functions always except, as a special case, it’s optional if there’s a single argument.
Re:Removing jQuery from GitHub.com frontend by floatboth on Wednesday July 25, 2018 @08:05PM (#17614061)
There's also the native Web Animations API!
Re:Removing jQuery from GitHub.com frontend by phyzome on Wednesday July 25, 2018 @05:33PM (#17613065)
Yeah, it doesn't serve the site well to include the animation and XHR stuff right at the top.

But if you had a small site that just needed to perform a few DOM manipulations, this would be highly relevant. If I just need to pop a div open and closed when a button is clicked, I sure won't bring in jquery just for that.

Re:Removing jQuery from GitHub.com frontend by vbezhenar on Wednesday July 25, 2018 @06:17PM (#17613432)
The reason I used jQuery is to have script working on every browser in the wild. Now that jQuery dropped support for old browsers, this advantage is no more (sure, I could use old jQuery, actually I'm doing exactly it, but I don't like to use outdated versions). I think that it was one of strongest point of jQuery and the that they decided to get rid of it is questionable decision.
Re:Removing jQuery from GitHub.com frontend by pferde on Thursday July 26, 2018 @05:59AM (#17616254)
It sounds like someone (motivated enough) should fork jQuery before the old browsers support got removed and maintain it as jQuery-legacy, backporting fixes from "new" jQuery" if applicable.
Re:Removing jQuery from GitHub.com frontend by Cthulhu_ on Thursday July 26, 2018 @05:36AM (#17616167)
That's one paradigm that operates directly on the DOM, but, a lot of modern-day development tools (e.g. redux) don't work like that, and their programming model is a lot more straightforward than "remove the selected property from all siblings", instead just having a selected boolean expression for each element.

The performance question becomes a bit more tricky too then, because instead of comparing direct DOM manipulation you're comparing 'rendering' as a more abstract concept.

Re:Removing jQuery from GitHub.com frontend by prophesi on Wednesday July 25, 2018 @08:12PM (#17614094)
While we're on the topic of our favorite JS toolsets, I've been having a blast using just a ES6 transpiler and Greensock. No need for neither jQuery nor a giant SPA framework.
Re:Removing jQuery from GitHub.com frontend by macca321 on Thursday July 26, 2018 @05:01AM (#17616062)
I don't think there's a good replacement for:

$(document).on("click", "#foo", function(){...});

either

Re:Removing jQuery from GitHub.com frontend by pawelk on Thursday July 26, 2018 @05:27AM (#17616141)
Event delegation was a thing before jQuery, and is not that hard to implement as a helper function, e.g.

https://jsfiddle.net/jbctqupz/

Re:Removing jQuery from GitHub.com frontend by benaadams on Thursday July 26, 2018 @05:11AM (#17616091)
Re:Removing jQuery from GitHub.com frontend by nailer on Thursday July 26, 2018 @05:58AM (#17616253)
Indeed its easy! But damn it gets boring having everyone patch the DOM with things that should be in the standard DOM API already by now.
Re:Removing jQuery from GitHub.com frontend by Vinnl on Thursday July 26, 2018 @06:24AM (#17616337)
Is that not simply

    document.getElementById('foo').addEventListener('click', function() { ... });

?
Re:Removing jQuery from GitHub.com frontend by combatentropy on Friday July 27, 2018 @02:07PM (#17627849)
The vanilla equivalent of:

  $(document).on("click", "#foo", function(){...});
is:

  document.addEventListener('click', function (ev) {
    if (ev.target.matches('#foo')) {
    
    }
  });
The advantage is that #foo can come and go (after page load be injected and removed and injected again, but the event listener must be registered just once.

Since the example is an ID (#foo) the advantage is less obvious. Something like a class (.foo) makes it clearer that there could be many, and it could get expensive to attach an event handler to each one --- though I'm guessing it takes hundreds before it becomes a big deal. But again, .foo's can come and go without having to worry about reattaching the event handler.

P. S. My library, https://github.com/combatentropy/listenup.js (31 lines)

Re:Removing jQuery from GitHub.com frontend by talmand on Thursday July 26, 2018 @10:51AM (#17617922)
Well, it could be. As long as #foo exists on the page at the time that line is executed. If you inject #foo into the page after load then the click event won't work.

The jquery example delegates #foo, so it can be injected in the page after load and the click event will still work.

But there are ways to mimic the behavior as another person has pointed out.

Re:Removing jQuery from GitHub.com frontend by AlphaSite on Wednesday July 25, 2018 @05:29PM (#17613029)
It does get much closer when you set the minim IE version to 10.
Re:Removing jQuery from GitHub.com frontend by scns on Thursday July 26, 2018 @05:50AM (#17616229)
Maybe the percentage of people browsin github on IE11 is 0%?
Re:Removing jQuery from GitHub.com frontend by Raglov on Thursday July 26, 2018 @04:29AM (#17615936)
It's rather ironic how in object-oriented programming chaining is considered a bad practice, e.g., breaking the Law of Demeter.
Re:Removing jQuery from GitHub.com frontend by andybak on Thursday July 26, 2018 @07:53AM (#17616703)
> breaking the Law of Demeter

How so?

You have an instance. You're allowed to call methods or access properties of that instance. You're not supposed to call methods or access properties of properties.

So chaining is just:

    $foo.something().somethingelse().blah();
At each point you're getting a new instance and accessing that. You're never reaching inside of a property of that instance.
Re:Removing jQuery from GitHub.com frontend by pwm on Thursday July 26, 2018 @04:47AM (#17616006)
If GP is correct re failure propagation then this is monadic composition vs. OOP object chaining.
Re:Removing jQuery from GitHub.com frontend by rado on Thursday July 26, 2018 @02:12AM (#17615386)
Bloat and slowdown for the customer is not worth the dev convenience and no library can fix poor work organisation.
Re:Removing jQuery from GitHub.com frontend by austincheney on Thursday July 26, 2018 @05:20AM (#17616116)
It isn't about writing code. As a developer writing code is your job. If writing a couple of extra lines of code makes you sad then perhaps this isn't your cup of tea.

For me it has always been about performance. jQuery is slow. Even way back in the day before JavaScript got fast you could access the DOM quickly if you knew what you were doing. Likewise DOM access could easily make your code 5 times slower if you didn't know what you were doing.

Since 2012 JavaScript has been fast in every major browser and querySelectors are a standard feature. Since about that time accessing the DOM has always been 10s-100s of times faster than using the standard querySelectors. In Firefox it is 10s of thousands of times faster. The standard querySelectors are faster than using modern jQuery.

To me this is the difference between a junior developer and a competent developer. Some people NEED the extra help. I understand that. If product quality and achieving a superior user experience are important though you will simply figure out a better way of writing code, especially since writing code is probably your job.

Re:Removing jQuery from GitHub.com frontend by yAnonymous on Thursday July 26, 2018 @06:00AM (#17616263)
Software development is a lot about making good use of resources and if you reinvent the wheel for every job you do, maybe it isn't your cup of tea.

I've worked with developers who completely ignored good libraries and instead created their own terrible implementations. They got nothing done and what they did was a buggy mess that often needed months of patching.

Finding a good middle ground is the best way to go and when the loading time increases by only a few milliseconds, but the development is a lot faster and cheaper, that's a good compromise in most cases.

Re:Removing jQuery from GitHub.com frontend by austincheney on Thursday July 26, 2018 @09:19AM (#17617188)
Cliche ad nausium. It’s like saying I should never have to write my name more than once, because it is reinventing the wheel.

In this case every call to the DOM goes from a slow baby crawl to rocket speed. In no other aspect of life do people make such empty excuses, using cliches no less, to intentionally remain in the stone age.

Re:Removing jQuery from GitHub.com frontend by talmand on Thursday July 26, 2018 @11:00AM (#17617977)
Well, considering there are devices out there for the purpose of signing names repeatedly, I would say your example doesn't necessarily work.

Totally depends on the situation.

And why the assumption that modern versions of jQuery don't make use of modern DOM APIs?

Re:Removing jQuery from GitHub.com frontend by austincheney on Thursday July 26, 2018 @11:12AM (#17618073)
Here is what makes jQuery slow, both now and in the past:

* querySelectors (standard or the home grown Sizzle engine)

* Method chaining for trivial tasks, in many cases to compute data that is already statically present or directly assignable.

Regardless of whether jQuery is using modern APIs or not there are old standards available, to JavaScript, that just about everything in jQuery eventually compiles down to. At the end of the day it becomes a matter of whether writing a couple of 3 line abstractions is far too hard of work or whether it is simply easier to push everything through 65k of jQuery purely for the sake of familiarity.

Re:Removing jQuery from GitHub.com frontend by posting2fast on Thursday July 26, 2018 @06:24AM (#17616338)
"friend to your coworkers, enemy to your craft"