Question

As far i know until now, the min version of a .js(javascript) file is obtaining by removing the unncessary blank spaces and comments, in order to reduce the file size.

My questions are:

  1. How can I convert a min.js file into a clear, easy readable .js file
  2. Besides, size(&and speed) are there any other advtages of the min.js file.
  3. the js files can be encripted?
  4. can js be infected. I think the answer is yes, so the question is how to protect the .js files from infections?

Only the first question is most important and I'm looking for help on it.
TY

Was it helpful?

Solution

  1. To convert a minified file into a editable source, simply open any IDE that supports auto-formatting and auto-format it. I use Netbeans to do this.
  2. If you do client side caching for the minified file, it means to say that the client (computer) needs to process less bytes. Size and speed are the main advantages of a minified file, and they are already great advantages to prepare for a future that requires great load of data transfer. By the way, it also saves you some bandwidth on your server and therefore money.
  3. I don't see the need of encryption. See How to disable or encrypt "View Source" for my site
  4. Javascript files cannot be edited unless it is done so on the server. The security of your Javascript files depends on your 1) server protection 2) data protection. Data should not be able to exploit. But of course, Javascript is executed on the client side, it will be meaningless for the client user to attack him/herself. However Twitter has shown multiple Javascript exploits. You need to constantly test and check your codes against XSS, CSRF and other attacks. This means to say that if your Javascript file has a loophole, it was the developer, you, who created it.

OTHER TIPS

  1. Multiple minifiers exists, that also are able to compress JS, see http://dean.edwards.name/weblog/2007/04/packer3 for one of the most being used. Some others exists, also see the JSMin library http://www.crockford.com/javascript/jsmin.html

  2. The main advantage is the size gain. You should also aggregate your JS files when you have multiple JS files, this also saves a lot of I/O (less HTTP requests) between the server and the client. This is probably more important than minifying.

I can't answer you about encryption. Client security will mainly depend on its browser.

EDIT: Ok my first answer is not for the first question, merged both in 2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top