loadjs icon indicating copy to clipboard operation
loadjs copied to clipboard

Add functionality to wait for document.ready?

Open W1zzardTPU opened this issue 7 years ago • 2 comments
trafficstars

What do you think about adding an internal dependency called "document", that's triggered by document.ready?

I faced random issues with jquery dependencies until I realized my jQuery code now got executed before the DOM was ready. Clearly a coding bug on my side, but it got me thinking.

My current workaround is

loadjs(["..."], 'jquery-pre'); 
loadjs.ready(['jquery-pre'], function() {
  $(function() { loadjs.done('jquery'); });
});

Not sure if worth the feature bloat for loadjs

W1zzardTPU avatar Jan 10 '18 06:01 W1zzardTPU

DOM timing with jQuery can definitely get tricky. I'm hesitant to add a jQuery-specific feature but I'll think about it some more. In case it helps you can combine your loadjs calls into one:

loadjs('/path/to/jquery.js', function() {
  $(function() {loadjs.done('jquery');});
});

// execute code after jQuery document.ready
loadjs.ready('jquery', function() {
});

amorey avatar Jan 10 '18 10:01 amorey

Yeah, that's what I'll use, was just waiting for the new release :)

W1zzardTPU avatar Jan 10 '18 10:01 W1zzardTPU