4 situations when not to use javascript
Sat, 05 Jun 2010 09:51:47 +0800from Articles
JavaScript is an awesome technology that many web designers and developers have used through out the years to create wonderful, interactive, and attractive websites. While I would be first to admit that JavaScript is very important when designing web pages that require functionality that HTML just simply cannot provide, there are too many web design related professionals (such as programmers) who have overused the technology in websites.
While the existence of JavaScript is a good thing, always remember that JavaScript is not an end-all solution to any problem a developer might encounter. Unlike duct tape, and more recently, the super glue, JavaScript cannot solve all conceivable problems by over applying the stuff. Okay, maybe it can. But still, it would soon get messy, and very unsightly.
The trick to using JavaScript effectively, is exactly how to effectively use super glue - apply just enough for it to do the job and use screws where appropriate. On top of my head, here are some situations when JavaScript should not be used.
1) When screws would work better
JavaScript is a powerful beast! It can let you format your HTML code on the fly, highlight important keywords when your mouse passes over them, calculate the distance between the sun and the earth, and some say it can also part the red sea - a feat done only once in the history of man. But, as powerful as JavaScript is, it is not always the best tool to use.
While we can do a lot of fancy formatting, and some cool effects with JavaScript, many times HTML with a combination of CSS can do a better job. Also, HTML with the CSS are the proper tools to use when we are doing things such as highlighting important keywords and formatting HTML content on the fly. Unless you are absolutely sure your HTML or CSS can't handle certain task, it is almost always better not to use JavaScript at all. Also, take note that in most browsers, unlike HTML, JavaScript can be disabled and things might not look right for all users.
If you are not trying do do something too fancy(such as parting the red sea), stick with HTML and CSS.
2) When you worry about absolute compatibility
A modern web site like the X-Men of software applications. While the X-Men is composed of team members with special powers, a web site is an application that is composed of components with special powers. A website mayl have HTML, CSS, RSS, server-side scripting, flash and the database working together in absolute harmony. And then we have Jubilee; the kid who dosen't really need to be there all the time but somehow keeping her around seems convenient - just like JavaScript.
While JavaScript (and Jubilee as well) can do some things other technologies can't, more often than not, other technologies can do these just as well. And they are often more supported by more browsers. In fact, for close to absolute compatibility, server-side scripting and an older HTML spec (which to me seems to be on the extreme side) should be used.
Most browsers today support JavaScript. But JavaScript can be disabled by the most popular browsers when it is becoming an irritating brat. Some older browsers (and some new ones too) may have radically different implementation of JavaScript that might make your page behave radically differently when viewed with these browser. Also, while most browsers support JavaScript, not all will. It is always good to investigate the possibility of using other alternatives to JavaScript such as you server-side scripting, or HTML and CSS for that matter.
3) When server side scripting is more appropriate
JavaScript can do a lot of things, we have established this. But some things that it can do, things such as ASP or PHP can do better. Of course you can make a very fancy page that checks if the phone numbers are actually valid numbers, or if your email are valid email addresses, but if you intend to save these things in your database, make sure these checks are done server-side or you will be asking for trouble.
4) When you can live without it
The biggest reason why not use JavaScript is when your page can exist without using it. If some feature can be implemented in PHP and work just as well(and you are using PHP anyways), then do it in PHP. The same goes with HTML and you CSS. While there are many reasons why we use JavaScript, the number one reason why we shouldn't use it is when we really don't have to use it.
When designing your website, always ask yourself if a technology is really necessary for the completion of the project. This includes flash and server-side-scripting (such as PHP and ASP). Not because you can, you should - this hold true specially when creating websites that are limited to a smaller budget.
