Saturday, 15 March 2014

javascript - LabJS and document.body.appendChild -



javascript - LabJS and document.body.appendChild -

i using labjs , in 1 of js file have document.body.appendchild(). appears work fine wondering if can suffer same potential async issues document.write or if behaves differently.

before doing document.body.appendchild(), need know dom has finished parsing attempting modify dom in way before done parsing can cause errors (you can cause browser segfault in versions of ie).

so, if using labjs load scripts dynamically , doing before document has been parsed, create issue of script loading , running before document finished parsing.

the usual ways prevent script running either not effort load until right before </body> tag or utilize sort of dom ready detection logic script gets notified when dom ready , runs logic when safe so. don't know labjs in detail know if has it's own dom ready detection logic (i didn't see such capability upon first look).

if using other framework (jquery, yui, etc...), has such logic. if not, there plain javascript docready() function here: pure javascript equivalent jquery's $.ready() how phone call function when page/dom ready it can utilize create sure dom-modifying code doesn't run early.

javascript asynchronous labjs

No comments:

Post a Comment