views:

617

answers:

3

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.

A: 

What does the rest of the page look like? What elements should be rendering that aren't? What other Javascript do you have?

What you have looks fine, but you will not be able to use methods in dojo.number or anything else loaded via dojo.require until after the page loads -- you must wait for window.onload to fire, or use the dojo.addOnLoad() method to trigger a callback. The latter is actually a bit quicker than onload.

dojo.require uses synch xhr to load which does block the browser, so if the load is unusually slow, you will notice a delay in the rendering of the page.

peller
As I wrote, the page does not render at all. Using methods in dojo.number is not the problem. And there is no delay in rendering. Firefox just doesn't.
Eduard Wirch
yes, but it might help to know what else is on the page, or what the simplest possible sequence is to produce this behavior. More than this snippet is required to reproduce the problem, and some interaction must be in play.
peller
A: 

We are experiencing the exact same problem with different pages of our system and the html in the page varies, as Eduard said seems to be a problem of the timing between the download of dojo resources and firefox rendering the page and not with the content in page, however the content in the page got to influence too seems it only happens in complex pages with a lot of html.

David
A: 

We are having the exact same problem. So the solution is to move all dojo.require statements from inline to window.load?

twest
(please use the comment functionality if you don't "answer" the question) Haven't found a good solution yet.
Eduard Wirch