0

Using the following, I can get the scripts start downloading in the correct order. But I believe that because some are larger than the others file size wise, you could have one start running out of order.

<script defer="defer" src="http://priatek-console/bower_components/highcharts/highcharts.js"></script>

<script defer="defer" src="http://priatek-console/libs/angular.js"></script>

<script defer="defer" src="http://priatek-console/apps/home/executive.js"></script>

So based on the above, I assume that executive.js (just a few lines, dependent on angular) finishes downloading before angular.js (combination of angular, animate, and ui bootstrap) and I end up getting this error AT RANDOM TIMES:

Uncaught Error: [$injector:modulerr] Failed to instantiate module executiveHome due to:
Error: [$injector:nomod] Module 'executiveHome' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Therefore, my final understanding is that defer will begin loading the scripts in order after the page itself loads, but it won't guarantee the order they will run in since some finish downloading before others.

Is there a simple way to fix this outside of concatenating the files or using something like require.js? I am using John Papa's style guide for my angular code and I haven't seen anything regarding this. Nor does it recommend using angular.bootstrap

jstudios
  • 856
  • 1
  • 9
  • 26
  • Why do you feel the need for `defer` in the first place? Have you tried simply placing your `script`s before the closing `body` tag, in the correct order? – Oka Feb 19 '16 at 19:20
  • Use `$q` and chain promises. – ryanyuyu Feb 19 '16 at 19:20
  • Is requirement to load scripts in order 1) highcharts.js, 2) angular.js, 3) executive.js ? – guest271314 Feb 19 '16 at 19:22
  • @Oka See answer #4 here: http://stackoverflow.com/a/25420553/3298753 – jstudios Feb 19 '16 at 19:22
  • @guest271314 At the very least, `executive.js` depends on `angular.js`. – jstudios Feb 19 '16 at 19:23
  • @jstudios Try loading scripts in order by checking if an object or variable within current script is defined in window before loading next script ; see http://stackoverflow.com/questions/26124199/run-custom-code-after-jquery-has-been-loaded-via-modernizr – guest271314 Feb 19 '16 at 19:33

0 Answers0