Alvin Alvin - 2 months ago 10
Node.js Question

gzip response for a single route

I ma using express and compression library:

var compression = require('compression')
var express = require('express')

var app = express()

// compress all requests
app.use(compression())


Question:


  1. How can I just add a gzip response for a single route?


    1. If may server is IIS 8 which is host at Azure web app, will compression work?



Answer
  1. How can I just add a gzip response for a single route?

You can inline it, as with any other middleware:

app.get('/route', compression([OPTIONS]), function(req, res) {
  ...
});

Be aware that the compression middleware maintains a default threshold of 1KB of data, below which responses won't be compressed. See the documentation on how to change this if required.

  1. If may server is IIS 8 which is host at Azure web app, will compression work?

I would assume so, but can't state definitively as I don't have any IIS/Azure experience. But why not try it out?

Comments