Scott, Kelly:
Patch file: selectionScript-onload-basetag.patch (against r1198)
Modified files:
M dev/core/src/com/google/gwt/dev/util/SelectionScriptTemplate.js
M dev/core/src/com/google/gwt/dev/util/SelectionScriptTemplate-xs.js
I'd like you to have a look at these proposed startup script changes. The goals are as follows:
1. Fix a bug that was keeping IE from respecting rebasing the application via the <base> tag.
2. Have the module's entry point fire as soon as the DOM is fully loaded, but before window.onload() fires (so that images and iframes don't keep the app from starting).
---
First, rebasing. We currently determine the module's base url using a series of tests in the selection script:
- We try to find the path of the selection script itself.
- If that doesn't work, we use the path part of
document.location.href.
- Finally, if the script path turns out to have been relative, we use the <img src='clear.cache.gif'> trick to get the browser to absolutify it.
This works on pretty much all browsers but IE, because most browsers canonicalize the src attribute of script tags. IE leaves it alone, however, causing us to (usually) fall back to document.location.href. The problem with this is that it doesn't take <base> tags into account. This patch addresses this issue by looking for the last <base> tag in existence as of the time the startup script is parsed. This is correct, because this will be the base tag in effect when the startup script was loaded. If another one is added later, the base can change, but that doesn't affect the startup script (I've confirmed this on all browsers).
---
Now, the onload problem. We all know about the onload issue -- namely, that it fires too bloody late, causing onModuleLoad() to be called only after all images and iframes are done loading. What we *really* want (IMHO) is to know when the *DOM* is ready, so that things like
RootPanel.get('id') will work properly.
This is tricky in practice, as only Firefox and Opera9 have the DOMContentLoaded event. On other browsers, we fall back to a 50ms timer interval, checking
document.readyState. Again, I've tested this code on all four browsers, and it does the right thing.