Sunday, October 17, 2010

The danger of Javascript

As I use more and more AJAX on my applications, and thus more javascript, I am impressed by the power of the language, but have one really large concern.

With server side programs, one has complete control over the environment, and the client, other than some CSS issues, is not that great an issue.

However, with javascript, the code is being executed by the browser, which means one is at the mercy of a limitless number of interpreters. I have found numerous cases where one browser worked differently than all the others, with real consequences. Such as:

  • IE7 cannot properly create radio buttons with a pure DOM creation of the objects. There is a workaround, but it is bizarre, and I would never have figured it out. Luckily someone else did (You have to add html code the document.createElement call)
  • Safari returns the typeof on an array of objects as a function. All the other browsers I tested return the typeof as 'object'
  • IE7 actually throws an exception if you mispess lightgrey in CSS.
And that was all just last week. I'm sure others have more examples.

So, while javascript really does turn web programming into an interactive environment, it comes at a price. And a question: When do you stop supporting older, non-compliant browsers? IE6 is off my list already, and I would do the same with IE7 - but I have too many users that are trapped on IE7 due to large scale use of terminal servers.