This is a bug in IE6, it's been documented for years. If you want to dynamically load scripts they have to be in their own <script></script> block. IE will not parse the file until it gets to a </script>. So if you want to dynamically load 5 script then you have to have 6 <script></script> blocks. If you do that they will load in the correct order 100% of the time. So the code must look like:

<script>
var sc = document.createElement ('script');
document.body.appendChild(sc);
sc.src = '';
</script>
<script>
var sc = document.createElement ('script');
document.body.appendChild(sc);
sc.src = '';
</script>
<script>
var sc = document.createElement ('script');
document.body.appendChild(sc);
sc.src = '';
</script>
<script>
var sc = document.createElement ('script');
document.body.appendChild(sc);
sc.src = '';
</script>
<script>
var sc = document.createElement ('script');
document.body.appendChild(sc);
sc.src = '';
</script>

If the code looks like this then it will load in order. Now the problem is making source code do this, not a easy thing, if even possible.

But without the script blocks, IE will take it's time parsing the files.

Jim


On 11/4/06, Alessandro Sala <[EMAIL PROTECTED]> wrote:
Hi Jim,

I have never used a document.write() to load a script dynamically. I create a DOM script object then set the src to the path of the script I want to load. IE will execute the script immediately.

var sc = document.createElement ('script');
document.body.appendChild(sc);
sc.src = '';


If you create a function out of this (recommended), the file is included in the DOM when it hits the next </script> tag. This is a bug in IE, you have to close a script in order for the newly created script to be included in the DOM.

Thank you for your advice. Unfortunately I already tried to use this technique but it doesn't work
reliably in IE while the document is being loaded.

Let me summarize the whole thing:

*The goal*
Making the source build of a qooxdoo application work when the document type is XHTML.

*The problem*
The standard qooxdoo source loader uses document.write() to add <script src="" tags to the document being loaded, but the XHTML DOM does not support document.write(), so both  FireFox and Opera fail to load the application. IE6 doesn't really support XHTML; if the document is served with the correct mimetype (application/xhtml+xml) it just shows the XML source, otherwise it parses the document as if it was HTML (since XHTML syntax is mostly compatibile with HTML 4), so document.write() works.

*The (up to now)  failed solutions*
At first try, I simply used what you suggest (createElement and appendChild), but I found that, while it's perfectly ok in FireFox and Opera, it doesn't work reliably in IE6.

The reason you, and others, see it working is probably because you create isolated script elements, that is scripts which don't depend one on another.

On the contrary, the source scripts for qooxdoo classes need to be loaded in the correct order, which is determined at compile time, and which is reflected in the order used by the includer  to to add script tags to the document being loaded.

Given this, the problem with IE is that, while the document is being loaded, script elements added by createElement and appendChild don't get parsed in the same order they are created, but in an apparently random order: I suppose that the loading of such scripts from the network happens asynchronously, so the parsing order changes depending on system load, network latency and other unknown factors.

This supposition is backed up by the fact that the problem disappears if you load the application locally from the filesystem (where the loading of files is probably synchronous), or if you insert an alert() after adding every script element (this suspends the execution, giving the added script the time to completely load before adding following one).

Mainly following suggestions from Sebastian, I then then tried several other techniques (see my previous posts): you can find the document I used to test at http://www.alessandro.sala.mclink.net/inctest/ .

Your suggestion is the second item (DOM-post): even if the first time the scripts happen to load in the correct order, if you keep reloading the page (or clicking on the relevant link) you will notice that sometimes the load order is wrong. Only the last link (document.write) always work.

Here we only have 5 script included, so the probability of  them being mis ordered is low, anyway it happens and if you download the page and the included scripts and test them with a local webserver the problem is even more evident; if you have much more scripts to load, such as qooxdoo classes (about 200), it is almost sure that some script will be loaded out of order, making the application fail to load.

There is a working solution indeed: the load order is guaranteed if using a series of synchronous XMLHttpRequests to load the scripts and the eval()-ing them: but this means that the scripts get merged into a single document, losing the reference to their source filenames and line numbers, so the error messages from the browser become not much meaningful; in addition you can no more effectively use tool like Firebug to ease the development of applications and of qooxdoo itself.

Given this, perhaps the only practicable solution is to keep using document.write() for IE6 while using DOM insertion for other browsers; it remains to see what will happen with IE7: does it really support XHTML, so document.write() will stop working? is the script loading order problem still present? If the answer to both  questions is yes, then we have a problem.

Sorry for the long message, but I hope this has clarified the problem a bit.

Cheers,
Alessandro





-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to