Hacker News new | past | comments | ask | show | jobs | submit login

Does caching help? If so, shouldn't getElementById do the same thing under the hood?



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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: