Why Was I Concerned?
How Did I Do It?
Quite simply, like so:
- I moved all the code to a new file, prorator.js.
- In its place, I added the following to the HEAD section of the HTML page
That's all there is to it!
What Happens Now?
When the page loads, the script code is returned to the visitor's Web browser. Since the SRC attribute of the SCRIPT tag acts like any other hypertext reference, the code behaves as it did when it was part of the page, and since it is within the scope of a SCRIPT tag, the code that lies outside the functions executes when the file loads, just as it did, so the lookup tables that the functions need are ready to go.
What Are the Benefits?
This simple change has two huge benefits.
- The code is already more secure, because a casual browser can neither steal the code for his own use, nor maliciously alter it, then claim that our code was defective.
- By placing the code outside the page, the text that we want searched and indexed by Google and other search engines moves to the top of the page, thus increasing its relevance index.
Obviously, I intend to apply this technique to several other pages that I maintain that contain code in them. First up is the home page of a marketing Web site that went live in November 2006. That page contains two huge tables that are used to pre-load a set of images, used in a slide show that is one of its key visual features.