Comments (8)
Hi! Your code above works perfectly for me, but since you didn't provide a static file to use, I cannot help much further.
Compression depends on three main things you didn't provide:
- What are the request headers you are sending to the server?
- What is the type of the file you are serving?
- What is the size of the file?
from compression.
Thank you for response. Here is curl of request
curl "http://my-server.com.angular.js" -H "Pragma: no-cache" -H "Accept-Encoding: gzip, deflate, sdch" -H "Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.65 Safari/537.36" -H "Accept: */*" -H "Referer: http://my-server.com/" -H "Connection: keep-alive" -H "Cache-Control: no-cache" --compressed
And response:
Accept-Ranges:bytes
Cache-Control:public, max-age=0
Connection:keep-alive
Content-Type:application/javascript
Date:Mon, 25 May 2015 21:32:56 GMT
Etag:W/"e90aa-1077232132"
Last-Modified:Mon, 25 May 2015 21:09:53 GMT
Server:Cowboy
Transfer-Encoding:chunked
Vary:Accept-Encoding
Via:1.1 vegur
X-Powered-By:Express
from compression.
Thank you. How big is the file (in bytes). By default we will not compress a file if it under 1kb. I can also see by your response you have a proxy between you and the server. This is the problem pretty much 100% of the time. Can you make the request directly to the server without going through the proxy?
from compression.
The size of file is 958KB. It does not work even if run node index.js on my computer
from compression.
Unfortunately everything works perfectly for me with the code you sent. This means that I will just have to await a PR from you that fixes the issue, unfortunately. I will await a PR with the fix :)
from compression.
I'm going to close this for now due to lack of reproduction. If you are able to figure out the issue and it turns out to be a bug in this module, a PR would be very welcome :) Here is the console session from when I tried to reproduce the issue with the information provided:
$ cat app.js
var express = require('express');
var compression = require('compression');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(compression());
app.use(express.static(__dirname + '/public'));
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'));
});
$ node -v
v0.10.33
$ npm i compression express
[email protected] node_modules\compression
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])
[email protected] node_modules\express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected])
$ mkdir public
$ node -pe 'console.log("/* " + new Buffer(958 * 1024) + " */")' > public/example.js
$ ls -lh public/
total 480k
-rw-r--r-- 1 user group 958k May 25 17:59 example.js
$ node app.js &
[1] 14108
Node app is running at localhost:5000
$ curl -XGET -I -H'Accept-Encoding: gzip, deflate, sdch' http://localhost:5000/example.js
HTTP/1.1 200 OK
X-Powered-By: Express
Accept-Ranges: bytes
Date: Mon, 25 May 2015 22:03:32 GMT
Cache-Control: public, max-age=0
Last-Modified: Mon, 25 May 2015 21:59:33 GMT
ETag: W/"ef815-3318529146"
Content-Type: application/javascript
Vary: Accept-Encoding
Content-Encoding: gzip
Connection: keep-alive
Transfer-Encoding: chunked
Please try to follow my console session above yourself to see if it reproduces for you. If following the above still shows Content-Encoding: gzip
in the response like mine does, then it didn't reproduce the issue. If there are adjustments you can make that reproduce it, please feel free to follow up with the full instructions to reproduce, in the format as above so I can reproduce.
from compression.
ok, thank you. I'll try
from compression.
I've had the same problem as well. Your test script worked for me, however. The difference seems to be using -XGET in the curl command. According to this page:
http://stackoverflow.com/questions/8498371/curl-get-and-xget
the difference is that -XGET forces curl to use a GET request. By default it is doing a HEAD request, which I guess doesn't get gzipped.
So it looks like compression is turned on, it just doesn't appear to be thanks to curl. Could you include instructions for using curl properly to verify gzip in the readme?
from compression.
Related Issues (20)
- Setting Vary header although caching is disabled HOT 1
- "drain" event listener leak when using res.once("drain"); can't use res.removeListener("drain") HOT 3
- compresssion doesn't work ,the vue.txt is 2m HOT 2
- Content-Type: application/json; charset=utf-8 No effect HOT 2
- Question: Why this middleware HOT 2
- Corrupted compressed .js-files for Mac OS / Safari -clients HOT 11
- Is compression working when node server is running on a container? HOT 2
- middleware fails when the request has more than 1 values for accept-encoding header HOT 2
- Is compression result cached? HOT 1
- change Transfer-encoding HOT 1
- Why does the data size increase after compression HOT 1
- Force size to be a minimum... HOT 2
- Chunked encoding is broken after using this middleware HOT 1
- Using a current debug version HOT 1
- Deflate backwards HOT 7
- Compression instrumentation (before/after compression hooks) HOT 2
- Angular Not Compressing? HOT 2
- compression not working json payload HOT 6
- Crash when compressing characters like ū HOT 1
- Express returns a non-compliant HTTP/206 response when gzip is enabled HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compression.