Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Lazy Loading Asyncronous Javascript (friendlybit.com)
28 points by philfreo on May 25, 2010 | hide | past | favorite | 3 comments


Another solution might be to set the sourcing of JavaScript in a timeout, e.g. setTimeout(_sourceJavascript, 300). I think this will bypass the blocking nature. This is only based on my intuition thought - it isn't tested.

--

It's also important to note that window.onload will only fire when everything is loaded (including scripts and large images). To bypass this problem you should use something like jQuery.ready(document) or Dean Edwards onload hack ( http://dean.edwards.name/weblog/2005/09/busted/ ).


Most scripts need access to the DOM, and waiting for the onload or domcontentloaded events ensure that the DOM has properly loaded when you run your script. Using setTimeout does not ensure that, so you can't really write a script tag then...


IIRC, the setTimeout trick only works if window.onload executes before your timeout fires.




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

Search: