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

Brian is a software architect and technology leader living in Niagara Falls with 13+ years of development experience. He is passionate about automation, business process re-engineering, and building a better tomorrow.

Brian is a proud father of four: two boys, and two girls and has been happily married to Crystal for more than ten years. From time to time, Brian may post about his faith, his family, and definitely about technology.