dojo.require() prevents Firefox from rendering the page

Posted by Eduard Wirch on Stack Overflow See other posts from Stack Overflow or by Eduard Wirch
Published on 2009-12-21T22:35:45Z Indexed on 2010/03/31 8:03 UTC
Read the original article Hit count: 573

Im experiencing strange behavior with Firefox and Dojo. I have a html page with these lines in the <head> section:

...
<script type="text/javascript" src="dojo.js" djconfig="parseOnLoad: true, locale: 'de'"></script>
<script type="text/javascript">
    dojo.require("dojo.number");
</script>
...

Sometimes the page loads normally. But sometimes it won't. Firefox will fetch the whole html page but not render it. I see only a gray window.

After some experiments I figured out that the rendering problem has something to do with the load time of the html. Firefox starts evaluating the html page while loading it. If the page takes too long to load the above javascript will be executed BEFORE the html finishes loading.

If this happens I'll get the gray window. Advising Firefox to show me the source code of the page will display the correct complete html code. BUT: if I save the page to disk (File->Save Page As...) the html code will be truncated and the above part will look like this:

...
<script type="text/javascript" src="dojo.js" djconfig="parseOnLoad: true, locale: 'de'"></script>
<script type="text/javascript">
    dojo.require("dojo.number");
</script></head><body></body></html>

This explains why I get to see a gray area. But why does this code appear there? I assume the require() method of Dojo does something "evil". But I can't figure out what. There is no write.document("</head><body></body></html>"); in the Dojo code. I checked for it.

The problem would be fixed, if I'd place the dojo.require("dojo.number"); statement in the window.load event:

<script type="text/javascript">
    window.load=function() {
       dojo.require("dojo.number");
    }
</script>

But I'm curious why this happens. Is there a Javasctript function which forces Firefox to stop evaluating the page? Does Dojo do somethig "bad"? Can anyone explain this behavior to me?

EDIT: Dojo 1.3.1, no JS errors or warnings.

© Stack Overflow or respective owner

Related posts about dojo

Related posts about firefox