Yes, it's definitely going to hurt performance at scale. Though you shouldn't worry about too much unless it's completely necessary to optimize and squeeze every single bit of efficiency for your CPU.
Optimization is good, but as soon as you allow it to become premature optimization, that's when you should reconsider your priorities. You wouldn't want to allow the latter to get in the way of making actual progress in software development.
I saw a tweet about this last week! Using document.querySelector('body') is actually more performant than using document.body. So I wonder if doing document.querySelector('#some-id') would still be faster than document.body! :)
Thanks for the heads up. Does using id's to link js to the DOM hurt performance (at scale)?
Yes, it's definitely going to hurt performance at scale. Though you shouldn't worry about too much unless it's completely necessary to optimize and squeeze every single bit of efficiency for your CPU.
Optimization is good, but as soon as you allow it to become premature optimization, that's when you should reconsider your priorities. You wouldn't want to allow the latter to get in the way of making actual progress in software development.
I saw a tweet about this last week! Using
document.querySelector('body')
is actually more performant than usingdocument.body
. So I wonder if doingdocument.querySelector('#some-id')
would still be faster thandocument.body
! :)I wonder if there's a jsPerf for that by now. I'm really curious to see which method is more performant.