Main Page

Intellectual Property Issues

In the rewritten code, a document fragment is created before the loop begins. Then, inside the loop, the list
item is created and the text node is added to it. The last step in the loop is to add the list item to the docu-
ment fragment. Because the fragment isn’t a part of the DOM document, no recalculation is necessary.
After the loop has executed, the list items are added to the list all at once by using the
method and passing in the document fragment (which, you’ll remember, appends the children of fragment,
not the fragment itself).
Keep this technique in mind whenever you are manipulating the DOM document. If you are going to be
making more than one change, it’s best to use a document fragment to store the changes before applying
them to the document.
Intellectual Property Issues
After you’ve made all your size and speed improvements, you still must consider protecting your intel-
lectual property. This is something traditional programmers don’t need to worry about because the end
product that is shipped to customers is compiled and fairly safe from reverse engineering. When ship-
ping your JavaScript code, you are actually shipping source code, making it public. Although copyright
notices and other legal wording can provide a small measure of protection in a court of law, it doesn’t
help you keep your code safe in the first place. So what’s a developer to do?
Obfuscating is the process of mixing up your source code to make it more difficult for prying eyes. ESC,
described earlier, does a small amount of obfuscating by replacing variable and function names. This is
the most basic form of obfuscating, but there are more.
The Dithered JavaScript compression utility (
) provides an added amount of obfuscation in a unique way: It extracts sequences of charac-
ters from the JavaScript code and replaces them with special markers. When the code is executed, these
markers are replaced using regular expressions and the entire code is evaluated. For example, consider
the DOM code example from the previous section:
var oUL = document.getElementById(“ulItems”);
var oFragment = document.createDocumentFragment();
for (var i=0; i < 10; i++) {
var oLI = document.createElement(“li”);
oLI.appendChild(document.createTextNode(“Item “ + i));
Deployment Issues
22_579088 ch19.qxd 3/28/05 11:43 AM Page 593

JavaScript EditorFree JavaScript Editor     Ajax Editor