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

Why do you still need a document ready function if all your scripts are loading after the html anyway?


The DOM will have been parsed if your scripts are at the end—but external components (links, imgs) may not have loaded yet.


The same is true whether or not you use a document.ready statement; you're thinking of window.onready, which fires once all images have been downloaded.


You are correct! Thanks. Been spending too long with document.readyState.


you meant window.onload


well its more of a legacy problem, we are used to using it everywhere, deferring external scripts is a fairly easy exercise but those tiny snippets everywhere that have $(doStuff) are more annoying to port


If all your scripts are before the closing </body>, the DOM will be ready by the time they execute, and you can safely ditch your legacy ready wrappers.




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: