Opened 12 years ago

Closed 12 years ago

#3714 closed defect (wontfix)

dojo.require after page load

Reported by: guest Owned by: James Burke
Priority: high Milestone: 0.9
Component: Loader Version: 0.4.2rc1
Keywords: version = 0.4.3 Cc: tjerk@…
Blocked By: Blocking:

Description

User: Tjerk Wolterink Email: tjerk@… ( the trac system always uses 'guest', i do not want that )

There is a problem with dojo.require for some libraries.

Normally you import all files using dojo.require like this

<script>

dojo.require(dojo.lib1);
dojo.require(dojo.lib2);
dojo.require(ownpackage.lib1);

</script>

But to prevent slow loading of pages i want to do it as follows:

<script>

dojo.addOnLoad(function() {
 dojo.require(dojo.lib1);
 dojo.require(dojo.lib2);
 dojo.require(ownpackage.lib1);
});
</script>

But this does not always work (for example for Editor2 widget). For my own package i get the following exception:

[Exception... "'Error: Could not load 'xdatasystem.form'; last tried '__package__.js'' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
dj_eval(undefined)dojo.js (line 108)
loadUri("/XDataSystem/standard/js/dojo/../xdatasystem/form.js", undefined)dojo.js (line 214)
loadUriAndCheck("/XDataSystem/standard/js/dojo/../xdatasystem/form.js", "xdatasystem.form", undefined)dojo.js (line 223)
loadPath("../xdatasystem/form.js", "xdatasystem.form", undefined)dojo.js (line 195)
loadModule("xdatasystem.form", undefined, undefined)dojo.js (line 353)
require("xdatasystem.form")dojo.js (line 421)
moduleHasPrefix()dojo.js (line 191)
loaded()dojo.js (line 239)
callLoaded()dojo.js (line 295)
modulesLoaded()dojo.js (line 288)
dj_load_init(load )

Now maybe more a question than a bug:

  • How do you prevent loading of javascript before rendering the page?
  • Is my way ( using dojo.addOnLoad ) the best one?
  • Should dojo.require work after page loading?

Change History (4)

comment:1 Changed 12 years ago by James Burke

Cc: tjerk@… added
Component: OpsPackageSystem
Milestone: 0.4.40.9
Owner: changed from Dustin Machi to James Burke
Priority: highnormal

Using the dojo.require() inside a dojo.addOnLoad() should work, and I've used it before. You have to be careful though, if you then want to do some work with code that was pulled in via a dojo.require(), you might have a problem because of bug #2765.

Also, you should not pull in code via dojo.require inside dojo.addOnLoad if that module that is dojo.required has document.write() calls in there. That will cause problems, since it will wipe out the page.

comment:2 in reply to:  1 Changed 12 years ago by guest

Replying to jburke:.

Also, you should not pull in code via dojo.require inside dojo.addOnLoad if that module that is dojo.required has document.write() calls in there. That will cause problems, since it will wipe out the page.

So module writers should never use document.write to prevent this kind of bug.. Maybe we could add a dojo-style-guidline to never use document.write but use dojo.body().appendChild instead..! Just an idea

Greets Tjerk

comment:3 Changed 12 years ago by liucougar

document.body is not available before the page is loaded, so document.write is necessary before onload is fired

comment:4 Changed 12 years ago by James Burke

Resolution: wontfix
Status: newclosed

Usage of document.write is discouraged in the xdomain loading notes. For liucougar's comment, if the module has the option to use document.body, the code should do a test for it, and use it if possible. Otherwise, the module will just have to be noted as something that does not work in a delayed loading situation. Marking bug as wontfix since it is more of an education issue. It is documented in the xdomain loading notes of things to watch out for, but realistically, I just have to bug module owners if I see a problem with a specific module.

Note: See TracTickets for help on using tickets.