I'm trying to lazy load javascripts, but I can't get it to work reliably. My pages load quite quickly and I want to keep it that way, so I'm not about to use a timeout to delay the loading. Besides document.readyState
, how do I ensure the DOM is genuinely ready for modification?
Method I:
poll readyState
createElement script
src = url
appendElement to head
Results:
IE8: always aborts
FF3: loads first time, aborts every other
Chrome: loads first time, aborts every other
Method II: (lazyload included in head tag)
- load with lazyload
Results:
IE8: always aborts
FF3: works
Chrome: loads first time, aborts every other