Late window.onload, defer, DOMContentLoaded and multiple source files
- From: jjl@xxxxxxxxx (John J. Lee)
- Date: Thu, 29 Dec 2005 22:53:50 GMT
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/2004/05/26/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
.
- Follow-Ups:
- Prev by Date: Re: IE 6, javascript:void(0) stops the webpage loading
- Next by Date: Re: day of month
- Previous by thread: Help Me Understand This
- Next by thread: Re: Late window.onload, defer, DOMContentLoaded and multiple source files
- Index(es):
Relevant Pages
|