Still, it's annoying when someone steals your entire CSS layout and all of your DHTML JavaScript code without so much as a thank-you. Certainly you can discourage such behavior by placing a copyright notice in a comment in all HTML, .css (style sheet) and .js (external JavaScript) files.
These three types of files have different syntaxes for creating comments that are ignored by the browser, but visible to anyone reading your code. In an HTML page, your notice might look like this:
<!-- Copyright 2005, example.com. All Rights Reserved. We will take legal action against those who copy our HTML content, CSS style sheets and JavaScript functions. -->
In a CSS file, your notice will look like this:/* Copyright 2005, example.com. All Rights Reserved. We will take legal action against those who copy our HTML content, CSS style sheets and JavaScript functions. */
And in a JavaScript .js file, your notice will look like this:// Copyright 2005, example.com. All Rights Reserved.
// We will take legal action against those who copy our HTML content,
// CSS style sheets and JavaScript functions.
Also, obfuscation comes at a price: obfuscated source code that others can't read isn't legible to you either. So you will have to keep a "pretty" version of your page for your private use in updating the page, and run the obfuscation program every time you make a change to your page.
But that's not the worst part: a ferociously obfuscated web page cannot be indexed correctly by search engines. In case you're not already clear on how important that is, it means that no one can find your website. And that's not an acceptable price to pay to protect your HTML code.
There is, however, one compromise technique that doesn't break search engines: removing newlines and unnecessary whitespace. Removing carriage returns so that the entire page becomes a single line is enough to frustrate casual thieves.
When removing carriage returns, bear these rules in mind:
1. You can't have comments in JavaScript code if you remove all carriage returns, because comments in JavaScript run from // to the end of a line. Once you remove all carrige returns, there is only one line, and the rest of your program gets commented out.
2. If you use the <pre> element in your HTML, be aware that removing carriage returns within <pre> will alter the appearance of your page, turning all of the content of <pre> into one line from the web browser user's point of view.
3. Carriage returns inside <textarea> are also significant.
In general, we don't recommend trying too hard to copy protect your HTML, JavaScript and CSS -- the cost is higher than the benefit, and in the end clever users can find ways around all of the copy protection schemes. But removing unnecessary whitespace is the best option for those who must have some protection for their source code. Just be sure to keep a "clean" copy for your own use. When you make edits in the future, you won't want to deal with a single line of 8,000 characters, either.
Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.
Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!
Follow us on Twitter | Contact Us
Copyright 1994-2012 Boutell.Com, Inc. All Rights Reserved.
