Unobtrusive JavaScript And Why it Matters

Sharing is Caring

Many more senior web developers can remember throwing tags all over the contents of websites and using tables for the presentation of content: these practices are said to be intrusive and a maintenance nightmare especially when the font colour should be pink instead of black on a header.

Unobtrusive JavaScript is another best practice for later maintenance of the site. Unobtrusive JavaScript involves removing the behaviour layer from the structure and content. Instead of having JavaScript mixed throughout the content it is either placed into an external file or placed into the head of the document.

The major advantage of the Unobtrusive JavaScript is that it can also be used for progressive enhancement and other techniques for browsers that offer advanced DOM 2 support. All JavaScript frameworks that I am aware of actively encourage Unobtrusive JavaScript as do many CMS and frameworks.

There are of course some issues with unobtrusive JavaScript because it does take more lines of script and requires discipline, and the use of good coding patterns.

Sharing is Caring