23.1. How and When to Use JavaScript

JavaScript is one of the easiest Web programming languages to use — it is built into the client, requiring no server technologies, and is a reasonably easy-to-use language. However, because a technology is accessible isn't always a good reason to use the technology.

23.1.1. The Case Against Using JavaScript

JavaScript is easy to use. It's built into most user agents, runs on the client, and can do miraculous things to documents. However, it's not a foregone conclusion that you should use JavaScript in your documents — there are plenty of data points to consider before automatically jumping in with JavaScript.

Many smaller footprint user agents (cell phones, PDAs, and so on) do not support JavaScript. Many more user agents have JavaScript disabled by default. The net result is that JavaScript is significantly less accessible today than it was in the early days of the Web and graphical user agents.

Those user agents that do support JavaScript cannot be counted on to adhere to any one standard. As previously mentioned in Chapter 21, there are at least four different Document Object Models implemented across the current user agents. Writing code that is truly cross-platform compatible is nearly impossible, very difficult at best.

What this means is that JavaScript cannot be relied on to perform medium- to high-level tasks, and its presence should never be relied on to use your documents.

The preceding statement assumes your documents are meant ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.