type attribute instead of
language, but really nothing has changed and this has led to problems.
The number one problem I see is the way we are required to attach event handlers to elements. Look at how CSS works: the style definitions are loaded ahead of time and as an element appears on the screen that matches a particular pattern, that style is automatically applied. You don’t need to wait until the page has been completely loaded and then apply a style specifically to an element; the browser does this for you.
onload or some alternative to
DOMContentReady. Though this decouples the layers better, there is a lag. It’s possible for the user to start clicking around on the page and have nothing happen because the event handlers haven’t been added yet. I think we can do better.
What if attaching events to elements worked just like assigning styles? What if you could tell the browser that a particular element should have a specific set of event handlers as soon as the element becomes available? This would free you from ever needing to call
defer attribute on the
<script/> element, but that just defers the downloading and evaluation until after the page has been rendered. So basically, the options we have are either parse and evaluate now or parse and evaluate later, and neither of those is sufficient.
Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.
Both comments and pings are currently closed.