148Part IIIDocument Objects ReferenceHow you reference the source (Crystaltech web hosting)
148Part IIIDocument Objects ReferenceHow you reference the source file in the srcattribute depends on its physical location andyour HTML coding style. In the preceding example, the .jsfile is assumed to reside in thesame directory as the HTML file containing the tag. But if you want to refer to an absoluteURL, the protocol for the file is http://(just like with an HTML file): A very important prerequisite for using script libraries with your documents is that yourWeb server software must know how to map files with the .jsextension to a MIME type ofapplication/x-javascript. If you plan to deploy JavaScript in this manner, be sure totest a sample on your Web server beforehand and arrange for any necessary server config- uration adjustments. When a user views the source of a page that links in an external script library, code from the.jsfile does not appear in the window even though the browser treats the loaded script aspart of the current document. However, the name or URL of the .jsfile is plainly visible (dis- played exactly as it appears in your source code). Anyone can then turn off JavaScript in thebrowser and open that file (using the http://protocol) to view the .jsfile s source code. Inother words, an external JavaScript source file is no more hidden from view than JavaScriptembedded directly in an HTML file. Browser Version DetectionWithout question, the biggest challenge facing many client-side scripters is how to programan application that accommodates a wide variety of browser versions and brands, each oneof which can bring its own quirks and bugs. Happy is the intranet developer who knows for afact that the company has standardized its computers with a particular brand and version ofbrowser. But that is a rarity, especially in light of the concept of the extranet private corporatenetworks and applications that open up for access to the company s suppliers and customers. Having dealt with this problem since the original scripted browser (NN2) had to work along- side a hoard of nonscriptable browsers, I have identified several paths that an applicationdeveloper can follow. Unless you decide to be autocratic about browser requirements forusing your site, you must make compromises in desired functionality or provide multiplepaths in your Web site for two or more classes of browsers. In this section, I give you severalideas about how to approach development in a fragmented browser world. While JavaScript support has stabilized to some degree when it comes to desktop Webbrowsers, the popularity of mobile phone and handheld Web browsers has complicated thematter; few compact Web browsers support JavaScript as of yet. Is JavaScript on? Very often, the first decision an application must make is whether the client accessing thesite is JavaScript-enabled. Non-JavaScript-enabled browsers fall into two categories: a) JavaScript-capable browsers that have JavaScript turned off in the preferences; and b) browsers that have no built-in JavaScript interpreter. Using the