Web design online - 147Chapter 13JavaScript EssentialsHiding scripts entirely? It may be

147Chapter 13JavaScript EssentialsHiding scripts entirely? It may be misleading to say that this HTML comment technique hides scripts from olderbrowsers. In truth, the comments hide the scripts from being rendered by the browsers. Thetags and script statements, however, are still downloaded to the browser and appear in thesource code when viewed by the user. A common wish among authors is to truly hide scripts from visitors to a page. Client-sideJavaScript must be downloaded with the page and is, therefore, visible in the source view ofpages. There are, of course, some tricks you can implement that may disguise client-sidescripts from prying eyes. The most easily implemented technique is to let the downloadedpage contain no visible elements, only scripts that assemble the page that the visitor sees. Source code for such a page is simply the HTML for the page. But that page is not interactivebecause no scripting is attached unless it is written as part of the page defeating the goalof hiding scripts. Any scripted solution for disguising scripts is immediately defeatable bythe user turning off scripting temporarily before downloading the page. All of your code isready for source view. If you are worried about other scripters stealing your scripts, your best protection is toinclude a copyright notification in your page s source code. Not only are your scripts visibleto the world, but so, too, are a thief s scripts. This way you can easily see when someone liftsyour scripts verbatim. One other option for minimizing other people borrowing your JavaScript code is to usea JavaScript obfuscator, which is a special application that scrambles your code andmakes it much harder to read and understand. The code still works fine but it is very hardto modify in any way. You would use an obfuscator just before placing your code online, making sure to keep the original version for making changes. One JavaScript obfuscatorthat has been available for several years is a shareware program called JavaScriptScrambler(http://www.quadhead.de/). Script libraries (.js files) If you do a lot of scripting or script a lot of pages for a complex Web application, you will cer- tainly develop some functions and techniques that you can use for several pages. Rather thanduplicate the code in all of those pages (and go through the nightmare of making changes toall copies for new features or bug fixes), you can create reusable script library files and linkthem to your pages. Such an external script file contains nothing but JavaScript code no This kind of tag should go at the top of the document so it loads before any other in-documenttag pair is required, even though nothing appears between them. You can mix