开发者

Confused: javascript.js code shows in Chrome?

My understanding was that only the javascript code placed inline in the HTML page would show, never the code stored in .js files

...and I had never seen in any browser code in a .js file show on the clientside...

until I started to use Chrome and noticed all my code is available for viewing???

  1. Have I been convincing myself the code is safe in .js files, when in fact it never was?

  2. and while on this subject can a res开发者_StackOverflowponder be totally clear whether the code in .js files can be hidden or not. I have read many posts that left me doubting whether it can be done or not.

. Some say to place it in a .js file on the server so it executes on the server...

--- using 'language=javascript' and an html line with 'runat server'? no idea how to do that.

--- But, would that not defeat the purpose of speed, and refresh since the server has to be accessed?

--- might as well code it in the code-behind???(C#, VB, php, ...)

. Some say use an AJAX call etc... but it seems others contradict that, saying the code lands on the clientside anyway thus will show? ...and I am assuming this would be a callback with no page redraw...


JavaScript is executed in the browser, this means the script has to be submitted to the client. So, of course anyone can view the code, wether it's happening in the developer tools, getting the direct link out of your html or, for example, using a http sniffer.

Altough, there are some methods to make the script unreadable for humans. Minifying your script is a good practice in general. It decreases file-size, so the client has to download less, speeding up loading time. After all, this does not really help making your script "unreadable" for users, there are a lot of deminifying services all around the web.

Still, there is another way: obscurifying (or obfuscate) your script. This replaces the code to make it unreadable. Unfortunately, I don't really have experience with using this technique, so I don't know how it would affect the performance of the js-code.

Maybe you want to have a look at this: How can I obfuscate (protect) JavaScript?


Javascript code can be seen even if its in a .js file the only thing you can do to make it little tough to understand is minify the js file.


Actually, javascript code stored in a separated file wont be shown directly; the user must explicitly type the name of the file in the address bar to see its content.

The only way to hide it is, as said before, to minify the file, which compress the file and make it unreadable for humans.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜