[Bese-devel] javascript

Lou Vanek vanek at acd.net
Tue Jun 27 01:11:52 UTC 2006


Alexander Kjeldaas wrote:

> On 6/27/06, Lou Vanek <vanek at acd.net> wrote:
> 
>> The following is what i use for clisp to delay javascripts
>> from executing until the page has finished loading.
>>
> 
> I'm no javascript expert, but do you have the HEAD/BODY
> placement of your scripts correct?
> AFAIU, these are the rules:
> You can't do any load-time modifications to the page
> from a script placed in the HEAD section.  All HEAD
> scripts can be asyncronously executed (or in order but
> independent of BODY and rendering of the page).
> That means you cannot have any script in the BODY
> section that calls scripts loaded from the HEAD section.
> So, if you want to do stuff at (the end of) load-time that
> calls some dojo magic, dojo.js must be loaded from the
> BODY section and not from HEAD.

Thanks!
I was sure I tried that, but it was several years ago.
It works (on windows at least) if you place the js script
load just after the opening body tag.
Results are flaky if you put the js load at the
bottom of the page, but that can be avoided.

> When events can start triggering, all HEAD scripts
> must be loaded, and it looks like your magic hooks
> all functions into an events-can-start-to-trigger-now event
> (onload or similar), but I don't see how this is different
> from loading dojo.js from the BODY section.

Empirically, I would have to agree with you.

> This is probably obvious, and in that case, sorry for
> the noise :-)

This 'noise' saves us a lot of work and perhaps a little embarrassment.

> Btw, with a real js-aware "compiler" or such, it should
> be possible to write a tree-shaker that could additionaly
> split js-functions into HEAD and BODY parts ;-).
> 
> astor

Moving all javascript load scripts out of HEAD and after the opening body
tag is a better solution since it's simpler than what I came up
with. Should probably make this part of a new <ucw:body tag.

Lou Vanek





More information about the bese-devel mailing list