I have the following script, where the first and third document.writeline
are static and the second is generated:
<script language="javascript" type="text/javascript">
document.write("<script language='javascript' type='text/javascript' src='before.js'><\/sc" + "ript>");
document.write("<script language='javascript' type='text/javascript'>alert('during');<\/sc" + "ript>");
document.write("<script language='javascript' type='text/javascript' src='after.js'><\/sc" + "ript>");
</script>
Firefox and Chrome will display before, during and after, while Internet Explorer first shows during and only then does it show before and after.
I've come across an article that states that I'm not the first to encounter this, but that hardly makes me feel any better.
Does anyone know how I can set the order to be deterministic in all browsers, or hack IE to work like all the other, sane browsers do?
Caveats: The code snippet is a very simple repro. It is generated on the server and the second script is the only thing that changes. It's a long script and the reason there are two scripts before and after it are so that the browser will cache them and the dynamic part of the code will be as small as possible. It may also appears many times in the same page with different generated code.