I put some thought into this last night and there are some interesting
questions raised:
By default, the IFrameLinker allows multiple modules to coexist on
the same page. To replicate this with scripts, you need to ensure that
all scripts are privately scoped. There are conflicts with privately-
scoped scripts and dynamically-loaded code. You can mutate the global
scope of a window, but I don't know of any way to add new identifiers
to the scope of a function used as a private namespace after that
function has terminated.
It is possible to evaluate code within an existing private scope. As
long as you can structure the symbol dependencies between runAsync
modules such that it can be represented as a DAG, two fragments never
providing visible identifiers for each other, you can load the various
modules as a tree of scopes. I'm not deeply familiar with runAsync,
so I don't know if it is always true. The worst-case end-result of
loading 10 different fragments, each depending on symbols from the
last n-1 loaded fragments would effectively be the equivalent of 10-
deep nested scope chain. I don't know what effect this would have on
performance.
Here's a summary of the linking options that I know of. I've added in
an alternative iframe linker that doesn't load HTML from a remote
source, but dynamically constructs the iframe contents and injects the
scripts into it:
1. Monolithic iframe (IFrameLinker):
Supports multimodule: Yes
Supports off-domain loading: No
Supports runAsync: Yes
Global namespace pollution: Only within the iframe
2. Dynamic iframe, injected with scripts, ie: create iframes
dynamically with src="javascript:;" and document.write()ing an HTML
document:
Supports multimodule: Yes
Supports off-domain loading: Yes
Supports runAsync: Yes
Global namespace pollution: Only within the iframe
3. Globally-scoped script:
Supports multimodule: No
Supports off-domain loading: Yes
Supports runAsync: Yes
Global namespace pollution: Yes
4. Privately-scoped script (XSLinker):
Supports multimodule: Yes
Supports off-domain loading: Yes
Supports runAsync: Possibly, but with potential size/speed consequences
Global namespace pollution: None
Matt.
> --
>
http://groups.google.com/group/Google-Web-Toolkit-Contributors