Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Caching jQuery selectors may result in a speedup, but as with all caching systems I've run into nasty, hard to trace bugs that were the result of stale cached jQuery selectors.

So I'd add the caveat to caching jQuery selectors that standard premature optimization rules still apply.



Caching them in local fucntion scope should be harmless. For instance: grabbing #x, using it inside a decision structure and iterator. Caching #x as a global constant is probably setting you up for some fun debuging later.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: