Say I have a script called makeFields.js which includes the method
function makeDateControls() {
document.write(/* ... */);
}
In my HTML, I link to that script in the head, like so:
<head>
<script type="text/javascript" src="makeFields.js"></script>
</head>
Then in my HTML, I have an inline script outside the head:
<div>
<script>
makeDateControls();
</script>
</div>
The question is: can I depend on the browser to wait for makeFields.js to finish downloading before it tries to call makeDateControls()? Does it matter whether I put the makeFields.js script tag in the head or in the body? Does the behavior depend on the presence of document.write()?
Although it seems like it wouldn't work, we haven't had any problems with this method as far as I can tell. Keep in mind however that I did not create this framework - I'm new on my team so change isn't easy.
document.write(). You'll have no idea where in the document the string is added.document.write()is contained in a function in an external script, but the function is called from an inline script. The question then is what effect this interaction has on the (a)synchrony of the page load. It seems to work, but I want to know how and/or if it's just a coincidence.<script src="jquery.js"></script> <script>$('div')...</script>works. That's the standard way of composing scripts.