2

I need a solution to obfuscate or minify my javascript code before the client loads any of my important javascript files. I need my code to have all the comments for future development, but load a minified or obfuscated version to my users.

The reason I want to do this is because my code is heavily commented. I need my comments for future updates, but I don't want prying eyes reading my comments as that's asking for trouble. Thanks!

Logical Nonsense
  • 393
  • 4
  • 17
  • you mean in runtime ? why don't you minify the files before deployment. – Shivaji Varma May 18 '18 at 06:27
  • The usual practice is to keep a plain version of your code for development, and also create a minified version that will be served to the browser. Gulp will help you with that. – Jeremy Thille May 18 '18 at 07:13
  • Possible duplicate of [How can I obfuscate (protect) JavaScript?](https://stackoverflow.com/questions/194397/how-can-i-obfuscate-protect-javascript) – Jeremy Thille May 18 '18 at 07:15

1 Answers1

1

I recommend Grunt for minification and concatenation of JS files (and other types).

Complete details on how to integrate minification using grunt-contrib-uglify.

If you also desire to concatenate your files and deliver one single file, check grunt-contrib-concat.

To speed up the development you should also use grunt-contrib-watch that allows you to watch over changes to your files and run the defined tasks.

Basic setup for minification:

grunt.initConfig({
    uglify: {
        my_target: {
            files: {
                'dest/output.min.js': ['src/input1.js', 'src/input2.js']
            }
        }
    }
});

Also check out the sample Grunt-file in which you should define all your tasks.

Catalin MUNTEANU
  • 5,618
  • 2
  • 35
  • 43