문제

I am facing issue with document.ready code due to async loading. For async loading I am using control.js http://stevesouders.com/controljs/

My js file, custom.js, is having code like:

jQuery(function(){
    jQuery('#keyword').autocomplete();
});

And my js file sequence is as below:

<script src="control.js" type="text/javascript"></script>
<script type="text/cjs" data-cjssrc="jquery-1.7.1.min.js"></script>
<script type="text/cjs" data-cjssrc="custom.js"></script>
<script type="text/cjs" data-cjssrc="jquery.autocomplete.min.js"></script>

So, due to file sequence, code is generating error. I don't want to change file sequence. Is there any way to fix this issue without changing file sequence?

What I was thinking is to use try-catch.

  • Whenever I get error on particular file,
  • I store it to some array ABC,
  • Execute next js
  • Execute js from array ABC, if Error, store to array ABC and recheck above steps.

Another thing I had in my mind to bind all the ready events, and execute it later once all scripts are loaded. But didn't find any robust solution.

Please let me know if you have any tips n tricks.

도움이 되었습니까?

해결책

Fixed :)

Changes may look like:

  • set obj.defineProperty to "loading"
  • Override event listerner
  • Load script
  • execute all the overridden events
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top