473,607 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Late window.onload, defer, DOMContentLoade d and multiple source files

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
"registerin g" 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
2 2418
On 2005-12-29, John J. Lee <jj*@pobox.co m> 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
(Oops, I forgot about my post...)

Jasen Betts <ja***@free.net .nospam.nz> writes:
On 2005-12-29, John J. Lee <jj*@pobox.co m> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
14698
by: Scott | last post by:
I'm new to ASP, but I've been programming in VB for several years, and I'm having a few issues with this ASP enhancement I'm working on. I've found ASP to be a lot different than what I'm use to in VB. I've created an ASP interface where a user can select an email group that populates a listbox with those email addresses. If a user sees an email in that list that they do not want then they can remove it by clinking the Delete button...
11
42803
by: Erwin Moller | last post by:
Hi group, I stumbled on something strange. I simplified the problem to this: A straightforward page with some JS: <span id="testid"> Hi
2
1450
by: John Derry | last post by:
I'm having a curious problem. I open a window with window.open method and supply a url which is a local file of file:/// form. After that, I go into the document of this new window to read the DOM for multiple forms which are defined in the html. The problem is that the objects are not immediately there. To make them available, I've found that if I do a View, Source from the new window's menu bar, THEN the DOM forms are there as expected....
2
5405
by: RobG | last post by:
There has been a bit of work done to get an init() function to run when the DOM is complete but before all the images have been downloaded. The idea is to kickoff init() scripts when all the elements are there but not wait for large images. Below is a script which uses 3 different techniques, one each for IE, Safari and Mozill/Opera 9. The Safari version uses browser sniffing, but I think with a little work that could be removed - the...
20
11857
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for (i=0;i<obj.length;i++) { obj.attachEvent('ondrag', noDrag); }
5
9432
by: lilOlMe | last post by:
Hi there! I'm developing some crazy Tab Control in .NET that uses JavaScript. A particular JavaScript method needs to be called during the window.onload event in order to initialize my Tab Control. The thing is that there can be more than one Tab Control on the page....and each one must be initialized during the window.onload event. Adding the JavaScript function call responsible for initializing a particular Tab Control to the...
0
7985
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8469
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8463
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6803
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4013
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2461
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.