Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to hide or scramble/obfuscate the javascript code of a webpage?

I understand that client side code must be readable from the browser but I wonder (since there are too many things that I ignore) if there are ways to obfuscate to code to the end user and, if not what is the best practice to "pack" the javascript code.

like image 276
0plus1 Avatar asked Apr 09 '09 14:04

0plus1


People also ask

Is it possible to obfuscate JavaScript?

JavaScript obfuscation is a series of code transformations that turn plain, easy-to-read JS code into a modified version that is extremely hard to understand and reverse-engineer. Unlike encryption, where you must supply a password used for decryption, there's no decryption key in JavaScript obfuscation.

Is it effective to drive to hide the source code of a page using JavaScript?

No. Javascript is sent as text to the browser: if the browser can read it, so can the user - or it wouldn't work at all.

Is it possible to obfuscate HTML?

No. The actual structure of the page is represented in the DOM, which is rendered by the browser. Necessarily, anything that is displayed on the page appears in the DOM and the DOM can be written out to disk (as HTML). Certainly, you can obfuscate JavaScript to make it difficult to read, but you can't hide it outright.

Is it possible to encrypt JavaScript?

Regarding client-side javascript code, which is what we usually see on the web, is unusable when put through an encryption scheme as the web browser needs to read the code so it can be interpreted by the browser. Usable javascript code is always trivial to view and get a copy of.

What is JavaScript obfuscation?

JavaScript code obfuscation is a series of code transformations that turn your exposed code into a protected version of the code that is extremely hard to understand and reverse-engineer.


2 Answers

It is good practice to minify your JS with a tool such as YUI Compressor. I would not obfuscate it unless you have a specific need to do this. There are plenty of online obfuscators such as this one

See this article: http://developer.yahoo.net/blog/archives/2007/07/high_performanc_8.html

like image 114
Chris Ballance Avatar answered Oct 17 '22 03:10

Chris Ballance


Check this out.

Other than min'ing it, I don't think you can really hide js. It all goes the user's browser and there are plenty of ways of seeing it once its there.

like image 25
Brian Avatar answered Oct 17 '22 04:10

Brian