soscripted / sox

Stack Overflow Extras: a userscript for the Stack Exchange websites to add a bunch of optional toggle-able features
http://stackapps.com/q/6091/
MIT License
72 stars 15 forks source link

What should SOX use: getElementByStuff or jQuery's $()? #451

Closed double-beep closed 4 years ago

double-beep commented 4 years ago

I have observed that SOX sometimes uses document.getElementByxxxxx():

https://github.com/soscripted/sox/blob/e36e62d1e3c41625d66107e16051a52845b986fc/sox.features.js#L15

However, sometimes (perhaps most of the times) it uses jQuery:

https://github.com/soscripted/sox/blob/e36e62d1e3c41625d66107e16051a52845b986fc/sox.features.js#L335

So, should SOX use document.getElementByxxxxx() or jQuery?

shu8 commented 4 years ago

SOX used to basically always use jQuery 's $() select function, but as it's started to get bigger I've found that the use of jQuery for simple selectors does have a slight performance impact (simply because jQuery does a lot more every time we try to select something) and so I've tried to start using vanilla JS when selecting elements with simpler selectors. See #391 for a few more details and (very rough!) stats.

In general, I think I'd now prefer:

for any new features.

I don't think there's any point in going over old code to replace jQuery because the effect will be quite small, but it's nice to have newer features being as 'efficient' as they can! :)