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.
Huh? http://youmightnotneedjquery.com/#replace_from_html and http://youmightnotneedjquery.com/#before show solutions that work in IE8+ and Edge.