HTML and CSS Reference
In-Depth Information
and it should be applied through external scripts. This means that inline scripts and
intrinsic event handlers are out of the question most of the time.
The advantages of this technique are vast:
Accessibility : A semantic document can make sense to a wider audience than
those with visual desktop browsers. Describing content with suitable tags
affords screen readers, search engine crawlers, and other user agents a better
chance of making sense of content.
Flexibility : The document structure can be more easily modified without
requiring change to external sources. The same kind of flexibility is achieved
in JavaScript and CSS. Scripts can be refactored, tuned, and modified without
requiring change to the underlying document. Script features can more easily
be reused for new document structures.
Robustness : Building on top of a solid foundation, behavior can be added
progressively. Applying feature detection, i.e., only adding features that can
be inferred to work, vastly decreases the chance of scripts blowing up and
ruining the user's experience. Such a defensive approach to scripting is also
known as progressive enhancement.
Performance : Using external scripts allows for better caching of scripts used
across web pages.
Extensibility : Separating scripts from the markup completely means we can
more easily add more progressive enhancement for new browsers as more
advanced functionality is made available.
9.2 The Rules of Unobtrusive JavaScript
Chris Heilmann is perhaps the most well-known advocate of unobtrusive JavaScript,
and he has written and talked extensively on the topic. In 2007 he wrote “The Seven
Rules of Unobtrusive JavaScript”:
Do not make any assumptions
Find your hooks and relationships
Leave traversing to the experts
Understand browsers and users
Understand Events
Play well with others
Work for the next developer
 
 
Search WWH ::




Custom Search