alt.www.webmaster Notes for Novices

 

Why You Can't/Shouldn't Hide Your Code

Hiding your HTML source code sounds like a great thing to the unsuspecting newbie, but as always there are two sides to every story.

People new to making web sites tell me "I've worked hard to make my pages, I don't want people to steal my code". This is fair enough, you have spent ages getting your CSS to work just right (more likely tables if you are a true newbie) and the pages are working just right in all the browsers you have tried. Why should you let other people steal what you have spent so long doing?

True enough, you can use various little techniques to try and make it difficult for people to take your code, but all of these techniques are fundamentally flawed.

Disabling the 'right-click' menu is one such way that people attempt to stop you from viewing their source code. It might work for some people running Internet Explorer, but this method is easy to bypass. Simply by holding the right-mouse-button and then pressing return before releasing the button will, in most cases, allow access to the context menu. You can also access the source code by selecting 'View > Source' (or similar) on the menu bar of most browsers.

The drawbacks of this technique are quite obvious. Firstly, it relies completely on JavaScript - so disable JavaScript and this technique is useless. Secondly, it doesn't work in some non-Internet Explorer web browsers - so some Netscape users are immune, as are a plethora of other browser users out there. Finally, the Apple Mac has no right-mouse-button - so how are you supposed to disable something that doesn't exist?

Another commonly used technique is to use JavaScript to encrypt your source code and write the contents to the browser window. This results in any attempt to view source being displayed as random letters and numbers. Disable JavaScript, however, and your page will be 100% blank. This means that your visitors will won't only be unable to see the source code, but they will also be unable to see the page! This method can also be overcome, but it is slightly more tricky.

As you can see, all of these methods rely on JavaScript - a technology that should not be abused. JavaScript is nice to add a few bells and whistles to a web site, but you shouldn't use it for mission critical functions of your site such as for printing the pages to the screen as in the second method.

Of course, there is a real reason why you shouldn't try to hide your code. the Internet is a way of sharing information and ideas - not hiding them - and if you don't want people seeing your ideas then you shouldn't put them on the web, but rather dig a big hole and bury them where no one can find them or better still keep them in your head. Once a visitor goes to your site, they download the whole page to their computer automatically and so they have a copy that they can do whatever the want to it.

Copyright laws pertaining to work on the Internet state that all of your published materials (i.e. original text, original images) is considered copyrighted as soon as you created and published it - it does not however extend to the source code of your site (i.e. HTML) and so you cannot stop people from copying your code, but you can do something about people stealing your text or images. As a general rule, if you believe that you need to protect your site in this way and stop people from being able to view the source, then you probably don't have anything that is actually worth stealing!

My personal belief is that you should let people use your source code in whatever way they wish. After all, that is how ideas spread and that is one of the fundamental principles behind the Internet! So stop trying to hide your code, and share it with the world.


Dylan Parry



Return to Notes for Novices  
Return to AWW Faq

W3C 4.01  W3C CSS  WAI-AAA