I am trying to enable gzip compression for my assets in a Sails.js (Node) application. When launching the app in production environment, all the assets in assets/linker/js
and assets/linker/styles
are concatenated, minified, uglified successfully (as specified in the Gruntfile). The following output files are generated:
.tmp/
public/
min/
production.js
production.css
I would like to add gzip compression as well, therefore i have installed grunt-contrib-compress and added the compress task to the Gruntfile. I can get the following results with successfully gzipped files.
.tmp/
public/
min/
production.js
production.js.gz
production.css
production.css.gz
My problem is now that the server needs to respond with the gzipped files (when the client accepts the encoding) instead of the normal ones and I can't find a way to do this. Maybe policies are the sails-way to do something like this? Or is there another way to use express middleware?
If it helps, this is the current sails-linker task which inserts the javascript production.js file into the markup:
...
prodJs: {
options: {
startTag: '<!--SCRIPTS-->',
endTag: '<!--SCRIPTS END-->',
fileTmpl: '<script src="%s"></script>',
appRoot: '.tmp/public'
},
files: {
'.tmp/public/**/*.html': ['.tmp/public/min/production.js'],
'views/**/*.html': ['.tmp/public/min/production.js'],
'views/**/*.ejs': ['.tmp/public/min/production.js']
}
},
...
Many thanks in advance.