Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 969
Alvin Avatar asked Jan 20 '26 10:01

Alvin


1 Answers

  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?

like image 133
robertklep Avatar answered Jan 22 '26 02:01

robertklep