Opened 12 years ago

Closed 11 years ago

#5887 closed enhancement (fixed)

Allow dojo to be added to the DOM after page load

Reported by: James Burke Owned by: James Burke
Priority: high Milestone: 1.1.1
Component: Loader Version: 1.0
Keywords: Cc: josh@…
Blocked By: Blocking:

Description (last modified by James Burke)

This is related to ticket #5432. However, that ticket wants a way for us to trigger dojo's "loaded" state even if someone clobbers our onload hooks.

This ticket is to track allowing dojo to be added to the DOM after the page load. So, in that case, the domcontentloaded/window onload has already fired. In that case, we can just use a timeout (hopefully) to trigger dojo's "loaded" state.

Change History (18)

comment:1 Changed 12 years ago by James Burke

(In [12492]) Refs #5887. Introduces djConfig.afterOnLoad: if set to true, then dojo._loadInit will be fired after a 1 second timeout. Using a shorter timeout (100ms) had problems where the dojo._loadInit was fired before all modules were downloaded. That seemed odd given the synchronous XHR calls. Also because of a bug in the dependency mapping stuff, had to rearrange how _base.js is organized. Testing on supported browsers looks good, although Opera in the xdomain case seemed to have a problem. Still need to investigate that a little more, and then write up release notes on the djConfig option.

comment:2 Changed 12 years ago by James Burke

(In [12659]) Refs #5887. Gets opera to work after page load in xd situation. Opera was downloading modules as part of the dojo.config.require section, which happened before dojo.i18n was downloaded in the xd case. Switch to using nifty conditional include build comments so we can load dojo.i18n for dojo.xd.js before the dojo.config.require section runs in _base/browser.js !strict

comment:3 Changed 12 years ago by James Burke

(In [12660]) Refs #5887. Gets opera to work after page load in xd situation. Opera was downloading modules as part of the dojo.config.require section, which happened before dojo.i18n was downloaded in the xd case. Switch to using nifty conditional include build comments so we can load dojo.i18n for dojo.xd.js before the dojo.config.require section runs in _base/browser.js !strict

comment:4 Changed 12 years ago by James Burke

Resolution: fixed
Status: newclosed

This is fixed now, with release notes updated too.

comment:5 Changed 12 years ago by James Burke

(In [12670]) Refs #5887: previous fix is not so good: means that svn source usage of dojo.js will load dojo.i18n by default. Backing out that fix.

comment:6 Changed 12 years ago by James Burke

(In [12671]) Refs #5887: make sure dojo.i18n gets placed before dojo._base.browser for dojo.xd.js so that dojo.config.require works in Opera in particular. !strict

comment:7 Changed 12 years ago by guest

Hi - I was going to try this feature out - I downloaded 1.1 and went to the test page referenced in the 1.1 release notes:

http://demo.sinkhole.intrcomm.net:8080/dojo1/dojo/_base/_loader/afterOnLoad.html

The error is:

"Could not load class 'dijit._Calendar'. Did you spell the name correctly and use a full path, like 'dijit.form.Button'?"

From the output in firebug it appears that _Calendar.js is being loaded in addition to dojo.js, dojo.css, etc.

Is the method shown in that test page the recommended way to use this feature as far as requiring modules?

Also, I noticed that there is nothing returned from the search page:

http://www.dojotoolkit.org/search/node/afterOnLoad

can you please add josh@… to CC.

Thanks,

Josh

comment:8 Changed 12 years ago by James Burke

Cc: josh@… added
Description: modified (diff)

This feature only works when using a built version of dojo, not if you run directly from the source distribution. Where you testing it via a built version of dojo?

comment:9 in reply to:  8 Changed 12 years ago by guest

Replying to jburke:

This feature only works when using a built version of dojo, not if you run directly from the source distribution. Where you testing it via a built version of dojo?

I noticed that comment from the test page - but I thought it meant you couldn't use it from a svn checkout. I'm using it from the 1.1 release drop on the downloads page (dojo-release-1.1.tar.gz) - is that not considered a "build"? I have a custom build that I also use with the dojo build scripts, does it require that?

Thanks,

Josh

comment:10 Changed 12 years ago by James Burke

Using either dojo-release-1.1.0.zip or dojo-release-1.1.0.tar.gz (the ones without the -src in the name) should work. I just downloaded dojo-release-1.1.0.zip, unzipped it, then ran dojo-release-1.1.0/dojo/tests/_base/_loader/afterOnLoad.html.

It seemed to work for me, but this was a quick test using Firefox 2.0 from local disk. Note if you are trying Firefox 3 beta, I believe you need to load the pages from a web server (FF 3 beta has an issue about loading files from file://).

How are you running the test page? Web server, file:// path, and what browser?

comment:11 Changed 12 years ago by guest

I was using this URL:

http://usnl-live.sinkhole.intrcomm.net:8080/dojo1/dojo/tests/_base/_loader/afterOnLoad.html

This is from dojo-release-1.1.0.tar.gz with firefox 2.

Firebug shows the following:

failed loading ../../../../dijit/_base/focus.js with error: Error: Could not load class 'dijit._Calendar'. Did you spell the name correctly and use a full path, like 'dijit.form.Button'?dojo.js (line 20) failed loading ../../../../dijit/_base.js with error: Error: Could not load 'dijit._base.focus'; last tried '../dijit/_base/focus.js'dojo.js (line 20) failed loading ../../../../dijit/_Widget.js with error: Error: Could not load 'dijit._base'; last tried '../dijit/_base.js'dojo.js (line 20) failed loading ../../../../dijit/_Calendar.js with error: Error: Could not load 'dijit._Widget'; last tried '../dijit/_Widget.js'dojo.js (line 20)

comment:12 in reply to:  11 Changed 12 years ago by guest

Replying to guest:

I was using this URL:

http://usnl-live.sinkhole.intrcomm.net:8080/dojo1/dojo/tests/_base/_loader/afterOnLoad.html

This is from dojo-release-1.1.0.tar.gz with firefox 2.

Firebug shows the following:

failed loading ../../../../dijit/_base/focus.js with error: Error: Could not load class 'dijit._Calendar'. Did you spell the name correctly and use a full path, like 'dijit.form.Button'?dojo.js (line 20) failed loading ../../../../dijit/_base.js with error: Error: Could not load 'dijit._base.focus'; last tried '../dijit/_base/focus.js'dojo.js (line 20) failed loading ../../../../dijit/_Widget.js with error: Error: Could not load 'dijit._base'; last tried '../dijit/_base.js'dojo.js (line 20) failed loading ../../../../dijit/_Calendar.js with error: Error: Could not load 'dijit._Widget'; last tried '../dijit/_Widget.js'dojo.js (line 20)

Couple other items:

FF is 2.0.0.13 Apache is 2.2.5 dojo1 is an Alias to the install path for the tar.gz

Josh

comment:13 Changed 12 years ago by James Burke

Milestone: 1.11.1.1
Resolution: fixed
Status: closedreopened

Thanks: it took a few tries but I was able to reproduce on a similar setup. There does seem to be a timing issue. First guess is that onload listeners are getting fired before the module loading is done.

comment:14 Changed 12 years ago by James Burke

Moving the afterOnLoad work to after the dojo.config.require work seems to do the trick. This should only be an issue with the normal dojo loader, since it does not block onload listeners via dojo._inFlightCount, as xdomain does.

Now need to make sure we put this work in only for hostenv_browser builds. I do not like having to split out this logic from hostenv_browser, but seems to be the easiest change to do. Could change normal loader to use dojo._inFlightCount. Something to consider too, but concerned about the amount of change needed for that.

If do it after the dojo.config.require work, it should also probably be done at the end of the dojo layer. That argues for a dojoGuardEnd.jsfrag section, maybe wrapped for a browser hostenv check.

comment:15 in reply to:  13 Changed 12 years ago by guest

Replying to jburke:

Thanks: it took a few tries but I was able to reproduce on a similar setup. There does seem to be a timing issue. First guess is that onload listeners are getting fired before the module loading is done.

Sounds good - the above URL should be accessible for a while, but sounds like you no longer need. If you want me to test a patch let me know.

Josh

comment:16 Changed 11 years ago by James Burke

(In [13534]) Refs #5887: move afterOnLoad kickoff after the dojo.config.require work in dojo._base.

comment:17 Changed 11 years ago by James Burke

(In [13535]) Refs #5887: move afterOnLoad kickoff after the dojo.config.require work in dojo._base. (merge to trunk)

comment:18 Changed 11 years ago by James Burke

Resolution: fixed
Status: reopenedclosed

(In [13536]) Fixes #5887: move afterOnLoad kickoff after the dojo.config.require work in dojo._base. (merge to trunk)

Note: See TracTickets for help on using tickets.