Forum Moderators: open
Luckydude
PS:- Actually, I WANT other people to see my code. That's why I put lots of comment in my code so that when people look at it, they can understand. It doesn't harm me, but if I write a clean code, someone can learn from me.
Just a thought..
compacted?
This "art" is also called code obfuscation.
btw - if you do it, consider this a "publishing" process. That is, keep a copy of the un-obfuscated code for bug-fixes and updates.
I save all my JavaScript files externally and call the .js file wherever I want to use it
That hides it for about 10 minutes.
When I view source of a page and see the external file, I just link directly to the file and download the entire JS file.
Microsoft has a ScriptEncoder which will slow people down. It's not a highly secure system, as there are script decoders out there as well which break the MS code, but for casual protection there it is.
[jimworld.com...]
Mark
Oh, and it is Javascript - not exactly a state secret. I am sure everyone uses techniques in their javascript they picked up from somewhere. (non third party) Client-side web development is forced to use an open model, by its very nature.
If the external js file is in a virtual directory or in a restricted directory shouldn't this prevent it from being downloaded?
Javascript is a client-side scripting language. This means that the clients (visitors) computer processes the script. If you hide your .js file in a restricted directory the clients computer wouldn't be able to access it.
that's why I put lots of comment in my code so that when people look at it, they can understand.
It is nice to have clean code and always a good idea to add a lot of comments to your code, but it isn't always the best idea to force visitors to download a bloated script on the off-chance that one of them may wish to view the source. The browser needs to read through the .js file before it can start rendering your page. So anything you can do to keep your externel css and javascript files small and compact is a good idea. You can always keep a source copy of your code for editing with all the comments and then just strip them out before uploading the file to your website.
If you are becoming a good coder and feel like you don't want people to copy your hard work you should consider looking into a server-side scripting language. This means the script is processed on the webserver and not the clients machines. This allows you to put your scripts into a restricted directory. Server side also allows you to add comments and such to your scripts without sending them along with the webpage.
Server-side scripting does have limitations and can't do certain things that javascript can. Another program that can imitate what javascript can do would be actionscript in flash. Flash creates a .swf file which only the flash player can read. It would look like jibberish to anyone trying to read it which would allow you to hide your source. Although I hear there are programs for reverse engineering flash scripts, but thats probably less comman than people stealing javascripts. You've probably already heard a lot about the evils of using flash so it's not exactly the perfect solution either.