Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use grunt-contrib-uglify to gzip the js files also?

I'm running a grunt task:

uglify: {
    options: {
        report: 'gzip'
    },
    all: {
        expand: true,
        flatten: true,
        cwd: 'js/',
        src: ['*.js', '!*.min.js'],
        dest: 'js/min',
        ext: '.min.js'
    }

}

The files are compressed onto one file, while running the report option

options: {
    report: 'gzip'
}

I see that the files would be significantly smaller when gzipped, but the output files are not gzipped, they are the size as per the "minified" report.

So the question is, how do I configure uglify to gzip the files also. Or is this a task for a different task?

like image 964
keeg Avatar asked Oct 25 '13 16:10

keeg


People also ask

What is grunt Uglify?

loadNpmTasks('grunt-contrib-uglify'); } Minification of JS files can now be achieved by running the command. grunt uglify. But a task, or a set of tasks, can be run together under an "alias task". The grunt.registerTask function serves this purpose.


3 Answers

gzipping is a technique used by a webserver to pack static assets, helping to reduce the size of transmitted data by half or more. The gzip report just lets you know how much the technique will save, but it is obviously unable to compress the file beyond normal minification. This post has some further information if you're interested:

http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

Personally I'd turn gzip reporting off since it doesn't perform well; perhaps only save it for when you're ready to deploy.

like image 191
Ben Avatar answered Oct 10 '22 07:10

Ben


You need to manually gzip files and set the response header "encode-type" to "gzip" if your hosting your files/assets on an S3. SO i need this feature as well as a grunt task to sync files or at the very least deploy files.

like image 21
Chito Avatar answered Oct 10 '22 07:10

Chito


You can add grunt-contrib-compress to your workflow and configure your webserver to use the gzipped version. On nginx that would be turning on gzip_static

like image 38
redben Avatar answered Oct 10 '22 05:10

redben