2

I would like to know if it's possible to pause the page processing till a certain script resource is loaded. But this is the complete picture:

Having many different scripts, some of them loaded using a wrapper and others loaded as just regular scripts like on this HTML:

<script type="text/javascript" src="/path/script1.js"></script>
<script type="text/javascript" src="/path/script2.js"></script>
<script type="text/javascript">wrapper.get('/path/script3.js');</script>
<script type="text/javascript">wrapper.get('/path/script4.js');</script>
<script type="text/javascript" src="/path/script5.js"></script>
<script type="text/javascript" src="/path/script6.js"></script>

The scripts loaded using a wrapper are always downloaded AFTER all the regular scripts are ready. At least this is what I'm experiencing on Firefox 18. The 'get' method of the wrapper does this to download the resources:

jQuery.ajax({
    url: 'url of the script',
    dataType: 'script',
    cache: 'true',
    async: false
});

The above scripts will load in this order:

  1. script1
  2. script2
  3. script5
  4. script6
  5. script3
  6. script4

So I would like to know if there is something I could do in the 'get' method of the wrapper to download them as:

  1. script1
  2. script2
  3. script3
  4. script4
  5. script5
  6. script6

Thanks in advance!

glezalex
  • 235
  • 2
  • 5
  • `async: false` Your users won't like that... – Waleed Khan Feb 14 '13 at 14:47
  • 1
    have a look at this, details how to load Javascript files pragmatically http://stackoverflow.com/questions/950087/include-javascript-file-inside-javascript-file a little bit of Jquery might be what you need so you can control load order yourself. – Phill Feb 14 '13 at 14:55

1 Answers1

1

You could wrapper.get be this:

function (url) {
    documen.write('<script type="text/javascript" src="' + url + '"></script>');
}
dave
  • 4,024
  • 2
  • 18
  • 34