Thursday, November 15th, 2007
From what I’ve seen, it appears that many developers, especially those new to the JS space are somewhat confused by the reasons for developing JS in an unobtrusive fashion. Typical arguments that I’ve heard are:
- It takes too long to develop
- If they don’t have JavasScript, then they’re out of luck
- We shouldn’t have to code for the 5% that don’t want to use an up-to-date browser
I’m sure many of you have heard similar comments and had many debates over the semantics of this topic.
Christian’s posting not only provides the reasons why it’s important but also includes example code that drives the idea home. Right off the bat, he makes several points that really make sense:
- You don’t expect browsers to support certain methods and have the correct properties but you test for them before you access them
- You don’t expect the correct HTML to be at your disposal, but check for it and do nothing when it is not available
- You keep your functionality independent of input device
- You expect other scripts to try to interfere with your functionality and keep the scope of your scripts as secure as possible.
I conducted a brief interview with Christian via email and here’s what he had to say:
What are the biggest challenges, in terms of unobtrusive JS, that you’re seeing in your work? Are you limited in what you can provide to
Has awareness grown? Do you see more developers actually understanding how to write unobtrusive JS and using it in practice?
With so many libraries out there at the moment, it’s natural for beginners to look for some help by using them. Has this impacted, negatively or positively, the application of unobtrusive JS techniques?
Neither nor I’d say. It depends on the library. I’ve been adamant to change some of the examples that come with the YUI to be unobtrusive, and I am in contact with other library developers to do the same. Whenever I’ve covered the topic of libraries in my books I also made sure the examples show how you can do things unobtrusively. It is a bit of a shame that a lot of libraries don’t wear that idea on their sleeves though, this is something I’d love to see. The release that made me the happiest was Dan Webb’s unobtrusive plugin for Ruby on Rails: http://www.ujs4rails.com/. It is up to people to start advertising the unobtrusive use of libraries more. I am currently doing that with an article series on dev.opera.com, and every publisher I am in contact with is crying out for books about using libraries. So if you are inclined to write, this is the time.
Posted by Rey Bango at 8:46 am