javascript - compess json data from rest node.js use express compression -


i created small application rest node.js. try compress data json, return request api, nothing compressed. use express , compression.

var express = require('express'); var methodoverride = require('method-override'); var bodyparser = require('body-parser'); var servestatic = require('serve-static'); var compression = require('compression');  var app = express(); app.use(compression());  app.use(methodoverride('x-http-method-override')); app.use(bodyparser.json()); app.use(servestatic('public', {'index': ['index.html']})); app.use('/', require('./routes'));  app.use(function(req, res) {     res.sendfile('public/index.html'); });  app.disable('x-powered-by');  var server = app.listen(3000, function () {     var host = server.address().address;     var port = server.address().port; }); 

this response header without compession =(((

http/1.1 200 ok content-type: application/json; charset=utf-8 content-length: 3756 etag: w/"56iqvwovcbb3mrndvdsfta==" vary: accept-encoding date: wed, 10 jun 2015 14:21:11 gmt connection: keep-alive 

help.

are using plain curl request it? tell curl ask compressed data:

$ curl -h 'accept-encoding: gzip,deflate' -v -o tmp http://localhost:3000/ * connected localhost (::1) port 3000 (#0) > / http/1.1 > user-agent: curl/7.37.1 > host: localhost:3000 > accept: */* > accept-encoding: gzip,deflate > < http/1.1 200 ok < content-type: application/json; charset=utf-8 < etag: w/"qiolme2descb3/8ol7nulg==" < vary: accept-encoding < content-encoding: gzip # <========================================== !!! < date: wed, 10 jun 2015 16:14:50 gmt < connection: keep-alive < transfer-encoding: chunked 

now download gzipped.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -