By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

Late window.onload, defer, DOMContentLoaded and multiple source files

P: n/a
I was cheered to see that this guy claims to have solved the problem
with onload only firing very late:

http://dean.edwards.name/weblog/2005/09/busted/
[Before anybody suggests it, I'm aware of HTCs, but it's not always
possible to use them.]

However, "ash" comments on that page:
The 'defer' attribute is a tricky little beast. Beware of
dependencies between scripts when using the 'defer'
attribute. i.e. if the 'onload' script in file2.js depends on
functions defined in file1.js, you should avoid adding a 'defer'
attribute to the script tag for file1.js.

The problems caused are infrequent, but are easily summarized by
saying you cannot guarantee functions will be available from a
deferred script until after 'onload' fires. Which is what you were
using 'defer' for in the first place.

If everything's in one big 'defer' script, you should be fine
though.

[...]

So, it's not possible to keep separate "behaviours" in separate
scripts? Different stuff like tab switching, tree view
expansion/contraction, etc. plus application-specific code, must all
be lumped together into on huge JS file? (OK, only the code actually
used by initialisation, but I can't immediately see how that makes
things much less painful for me.) Did I understand that right?

Somebody also seemed to suggest that this technique breaks
"registering" onload callbacks
(eg. http://simon.incutio.com/archive/200.../addLoadEvent), but I
haven't tried to work that one through yet.

If I do understand that right, I wonder about another approach.
Somebody else on that page suggested a timer combined with a "dummy"
element at the bottom of each page. You use a timer to poll, and when
the dummy element turns up in the DOM, that's when you do your
initialisation. Does anybody here have links to discussion /
implementation(s) of that idea?

Thanks in advance for any help,
John
Dec 29 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2005-12-29, John J. Lee <jj*@pobox.com> wrote:
If I do understand that right, I wonder about another approach.
Somebody else on that page suggested a timer combined with a "dummy"
element at the bottom of each page. You use a timer to poll, and when
the dummy element turns up in the DOM, that's when you do your
initialisation. Does anybody here have links to discussion /
implementation(s) of that idea?


??? what's the problem again? defer causes scripts to load or execute late
onload should be sufficient for the loading of the document.

you could use callbacks to detect the loading of statically loaded scripts
I expect they also support onload, dynamically loaded scripts seem to
support onload.

Bye.
Jasen
Dec 30 '05 #2

P: n/a
(Oops, I forgot about my post...)

Jasen Betts <ja***@free.net.nospam.nz> writes:
On 2005-12-29, John J. Lee <jj*@pobox.com> wrote:
If I do understand that right, I wonder about another approach.
Somebody else on that page suggested a timer combined with a "dummy"
element at the bottom of each page. You use a timer to poll, and when
the dummy element turns up in the DOM, that's when you do your
initialisation. Does anybody here have links to discussion /
implementation(s) of that idea?
??? what's the problem again? defer causes scripts to load or execute late
onload should be sufficient for the loading of the document.


The problem with using onload is described in the page I referenced in
my original post here. That page attempts to (and claims to succeed)
find a way of initialisation code at the earliest opportunity:
ie. when the DOM is loaded, but before objects such as images are
loaded (but without filling the HTML document with onfoo="bar"
callback bindings).

you could use callbacks to detect the loading of statically loaded scripts
I expect they also support onload, dynamically loaded scripts seem to
support onload.


The pages I referenced discuss, and reject, at least one way of making
use of script elements to solve the problem. IIRC, the problems are
related to cross-browser compatibility. What specifically did you
have in mind?
John
Jan 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.