javascript - How to only wait for document.readyState in IE and fire instantly for all other browsers? -


i have written css , javascript lazyloader dynamically load resources seperate pagelets (in way facebook renders page it's bigpipe technology).

in short html frame rendered first, separate parts of page generated asynchronously server. when each pagelet arrives pagelets css loaded first, innerhtml set, load required javascript pagelet , initialise it.

everything works , perceived load time pretty instantaneous given page.

however in ie, occasional method not support method or property when initialising scripts.

i have solved checking document.readystate before loading scripts.

now isn't huge issue adds on average 170ms pageload in chrome or firefox. not needed.

  function loadscripts(init){          // ensure document readystate complete before loading scripts         if( doc.readystate !== 'complete'){             settimeout(function(){                 loadscripts(init);             }, 1 );         }         else{             complete++;             if(complete == instance.length){                             var scripts = checkjs(javascript);                 if(scripts.length) {                     lazyload.js(scripts, function(){                                             runpageletscript();                         (var = 0; < scripts.length; ++i) {                             tc.loadedjs.push(scripts[i]);                         }                     });                 }                 else{                     runpageletscript();                 }             }         }      } 

what looking modification script implement 'wait' in ie, if other browser fire straight away. cannot use jquery utility $.browser , need tiniest possible method. hate use form of browser detection appears though solution. said if can come way, fantastic.

any suggestions gratefully received.

you use jscript conditional compilation, available in ie browsers (up ie10).

because it's comment, it's best place inside new function minifiers might remove it, changing code. though in general should avoid using new function, in case there's not other way prevent minifiers removing it.

example:

var isie = !(new function('return 1//@cc_on &0')()); 

however, seems main issue dom hasn't loaded yet -- make sure has loaded before running loader using domcontentloaded event (ie9+):

document.addeventlistener('domcontentloaded', function () {     // perform logic here }); 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -