G
Garrett Smith
Richard said:Garrett said:Thomas said:Garrett Smith wrote:
kangax wrote:
Thomas 'PointedEars' Lahn wrote:
Martin Rinehart wrote:
But don't event handler attributes have their own problems
- notably a somewhat idiotic scope augmentation?
Wouldn't it be recommended to use something along these lines:
[snip]
The approach of assigning an event handler via script separates
the attachment from from the content, so the script can be moved
around to different place in the document.
And completely separating the function from the markup it is
operating on (and with) is a Good Thing, because ...?
"so the script can be moved around to different place in the
document"
That is not much of a justification. For a start it is not true; you can
move the functions that are created from intrinsic event handlers around
if you wanted to.
Given a script "a.js" where a function |a| is defined inside it, and
then referenced in an event handler:
<script src="a.js"></script>
</head>
<body>
<p onclick="a()">...</p>
....
no problem, but if someone went and moved the script to the bottom,
</head>
<body>
<p onclick="a()">...</p>
...
<p>a lot of images, iframes, et c in this document...</p>
<script src="a.js"></script>
if the user clicks the p before a.js is loaded, the result would be an
error.
A better justification would being able to use the same code with many
intrinsic events without suffering the overhead of creating many
function objects. Though someone is likely to mention event delegation
in response to that
Bubbling ("delegation") could be done either way.
<snip>
That story gets put about as if it is some sort of universal panacea.
The decision to move the script to the bottom means that the html
elements reference the script via event handlers. The element appears
visually to the user before it is scripted. The interactivity that the
script would provide will appear soon after.
When the contents that the reader is interested in are at the top of the
document then putting them where they can be read as soon as possible
might be a good ides. But it can be an irritating pain if what you are
interested in is at the bottom of the page (such as the latest comments
on a blog that you have already read) and the loading of the scripts at
the bottom of the page block the ability to scroll. In that case I would
rather not have the top of the page sitting there taunting me while the
browser is not allowing me to scroll to what I am interested in.
Which browser does an external script block scrolling?
It may be that the real issue is attempting to download too much script
code, and playing around with where that code is loaded is just playing
with the symptoms rather than addressing the cause.
I have seen network latency for 1x1 gif that took over 7 seconds to
load. This was a feature of an advertisement. It had the effect of
keeping the browsers progress bar from completing.
Reducing the file size matters, but will not prevent blocking. The
blocking includes the duration of latency.
Garrett