Logical Nonsense
Logical Nonsense

Reputation: 413

Javascript minify or obfuscate code before browser loads JS

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!

Upvotes: 2

Views: 2143

Answers (1)

Catalin MUNTEANU
Catalin MUNTEANU

Reputation: 5634

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.

Upvotes: 2

Related Questions