JavaScript - - By Kevin Yank

JavaScript Isn’t Evil

The following is republished from the Tech Times #159.

Following my Avoiding Evil JavaScript editorial last issue, I got a great deal of contradictory feedback. It’s not surprising, given the strong opinions that people tend to have about accessibility and its importance on the Web.

Nevertheless, before I show you some easy and practical ways to write better JavaScript, I’d like to clear up one common misunderstanding that I found in some of that feedback.

JavaScript itself is not evil, nor are the web sites and applications that provide a slick, enhanced user experience using JavaScript. What I call “evil” is the use of JavaScript in such a way that it needlessly prevents some users from being able to access the site or application.

It’s usually not only possible but quite practical to build your slick, JavaScript-powered user experience on a foundation of standard HTML and CSS. This foundation enables you to deliver your site’s content not only to users browsing with JavaScript disabled, but also to automated systems like search engines.

With a little extra thought, you can even make your JavaScript functionality play nicely with assistive technologies, and work well for keyboard-only users.

But things start to fall apart when Ajax enters the picture, and users begin clamoring for the desktop-like applications that it makes possible. Often, static HTML/CSS is not up to the task of providing a useful foundation for these apps, and building a non-Ajax alternative would be a completely separate project — probably one that you can’t justify the cost of developing and maintaining. In extreme cases, it’s possible that what your application does simply doesn’t translate to the page-based model of plain HTML.

The solution to this dilemma, in my mind, is to separate these types of applications from the current, page-based Web, and move them to a “Web of Applications” that’s just as universally available as the Web is now, but which is designed from the ground up with applications in mind, and solves all the issues that are currently being caused by our attempts to shoehorn desktop-like applications into a system that was designed for serving pages of information.

This “Web of Applications” could be as simple as a new URL protocol (hatp:// for HyperApplication Transfer Protocol?) or MIME type that would be recognized by browsers, and in fact a number of vendors have attempted (or are planning to attempt) exactly this:

Meanwhile, the W3C is also working on this problem through the Web Application Formats Working Group.

So far, every one of these initiatives has failed to attract widespread adoption because it required the installation of some specific piece of software in addition to a web browser (in the case of XUL, it required a specific web browser). Unless they can achieve the same ubiquity as HTML, CSS, and JavaScript, desktop-like applications masquerading as web pages will remain the more popular—and problematic—choice.

So, in the absence of a suitably ubiquitous platform for desktop-like applications, do Ajax-powered desktop-like web applications fall under the umbrella of “Evil JavaScript?” Personally I think they do, but depending on your particular situation, they might be a necessary evil.

The evolution of web technology marches on, but as developers we need to do the best we can with the technology and resources at our disposal today. The most important thing, in my books, is that you make sure you’re well informed before you make a decision that might prevent some users from accessing your site.

Sponsors