Closed Bug 642063 Opened 13 years ago Closed 13 years ago

dynamic load problem of Javascript

Categories

(Tech Evangelism Graveyard :: English US, defect)

defect
Not set
major

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 612332

People

(Reporter: tim, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.67 Safari/534.13
Build Identifier: 4.0 (RC)

Debug version of GeoExt seems to reveal a problem with dynamic loading of Javascript:
When I load my development version of a GeoExt application into FF4RC, it crashes with a "class not found"-error. I had written my own class, which extends

Reproducible: Always

Steps to Reproduce:
1. Put OpenLayers and GeoExt (debug versions where scripts are loaded dynamically) libraries onto html page.
2. Make own .js file where you extend a GeoExt class that is loaded dynamically.
3. Open html page in Firefox 4 RC with Firebug installed to see that the extended class is non-existent at the time that your .js file is loaded, although GeoExt appends .js files before your script.
Actual Results:  
Nothing, resulting page does not load dynamic (dhtml) content. Maybe to do with Javascript engine optimization.

Expected Results:  
Page displayed like in IE, Firefox 3.6 or Google Chrome

I am a web developer in Palmerston North New Zealand and a fan of Firefox, mainly because of its speed and developer-friendliness. Like (Google) Chrom(e|ium) as well because it seems even faster than FF. But 4.0 might be great when it's complete.

Dynamic loading of Javascript will become increasingly important as more and more web apps exploit this feature and will become faster to load.
My blog is here: http://www.ihostnz.com/blog website at http://www.ihostnz.com
This comment is sent with the Firefox browser that I used when discovering the bug.

Firebug reports Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0
Version: unspecified → 4.0 Branch
Seems like I cannot reproduce it today. But I will try again. Maybe it needs more complexity in the code than I had thought.
OS: Windows XP → All
I have successfully reproduced the bug with a standard library (OpenLayers). Please take the time to look into it, as it is a show-stopper for anyone using dynamic loading of Javascript. I uploaded the example with screenshots here:

http://wiki.zen.landcareresearch.co.nz/ff4bug/
Message in the error Console:
Error: OpenLayers.Map is not a constructor
Source File: http://wiki.zen.landcareresearch.co.nz/ff4bug/bug.js
Line: 3

Reproduced:
Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Mozilla/5.0 (X11; Linux x86_64; rv:5.0a2) Gecko/20110506 Firefox/5.0a2
Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110506 Firefox/6.0a1

Works for me:
Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17


Regression range:

Last good nightly: 2010-09-17 First bad nightly: 2010-09-18

Pushlog: http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=268ef4ccb5ff&tochange=fc8d8dfee20f
Whiteboard: [bugday-2011-05-06]
Version: 4.0 Branch → Trunk
Assignee: nobody → general
Status: UNCONFIRMED → NEW
Component: General → JavaScript Engine
Ever confirmed: true
Product: Firefox → Core
QA Contact: general → general
OpenLayers has this wonderful code (starting line 321 of OpenLayers.js):

        var agent = navigator.userAgent;
        var docWrite = (agent.match("MSIE") || agent.match("Safari"));
        if(docWrite) {
            var allScriptTags = new Array(jsfiles.length);
        }
        var host = OpenLayers._getScriptLocation() + "lib/";    
        for (var i=0, len=jsfiles.length; i<len; i++) {
            if (docWrite) {
                allScriptTags[i] = "<script src='" + host + jsfiles[i] +
                                   "'></script>"; 
            } else {
                var s = document.createElement("script");
                s.src = host + jsfiles[i];
                var h = document.getElementsByTagName("head").length ? 
                           document.getElementsByTagName("head")[0] : 
                           document.body;
                h.appendChild(s);
            }
        }
        if (docWrite) {
            document.write(allScriptTags.join(""));
        }

So it runs totally different code in IE+Safari+Chrome on the one hand and every other browser on the other hand.  Now it happens that the IE+Safari+Chrome behavior works in every single browser... and if they were using it for all browsers things would Just Work.  But they're using different code for other browsers, and the different code only works in browsers that don't implement the script-loading semantics HTML5 specifies.  Which is why it doesn't work in Firefox 4.

This library just needs to rip out that doctype switch and run the "docWrite" version of the code in all browsers. 

Tim-Hinnerk Heuer, did you original code use this sort of pattern too?
Assignee: general → english-us
Component: JavaScript Engine → English US
Product: Core → Tech Evangelism
QA Contact: general → english-us
Whiteboard: [bugday-2011-05-06]
Version: Trunk → unspecified
Ah, looks like http://osgeo-org.1803224.n2.nabble.com/OpenLayers-2-11-release-schedule-td6091848.html is the thread discussing this.  So presumably this bug is a duplicate...
Whiteboard: DUPEME
The current workaround is to use the single-file version of OpenLayers.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → DUPLICATE
Whiteboard: DUPEME
Product: Tech Evangelism → Tech Evangelism Graveyard
You need to log in before you can comment on or make changes to this bug.