News for hackers. Stuff that matters.
Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$ by jonathrg on Wednesday October 02, 2024 @06:19PM (#41725481)
Does caching help? If so, shouldn't getElementById do the same thing under the hood?
Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$ by akira2501 on Wednesday October 02, 2024 @06:39PM (#41725590)
It used to more in the past.

The native call does usually include a cache and will use it optimistically; however, the strategies around invalidating this cache are varied and some surprisingly basic DOM actions can trigger it. Then browsers usually fallback to the full DOM query case.

The cache eliminates this variability, which prior to flexbox, could be very useful in highly nested site designs particularly in mobile contexts.