Am I wrong in finding that Node.js does no gzip compression and there are no modules out there to perform gzip compression? How can anyone use a web server that has no compression? What am I missing here? Should I try to—gasp—port the algorithm to JavaScript for server-side use?
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- google-drive can't get push notifications
- iOS (objective-c) compression_decode_buffer() retu
- How to reimport module with ES6 import
- Why is `node.js` dying when called from inside pyt
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How to resolve hostname to an ip address in node j
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
- Get file created date in node
Node v0.6.x has a stable zlib module in core now - there are some examples on how to use it server-side in the docs too.
An example (taken from the docs):
While as others have right pointed out using a front end webserver such as
nginx
can handle this implicitly, another option, is to use nodejitsu's excellent node-http-proxy to serve up your assets.eg:
This example demonstrates support for gzip compression through the use of connect middleware module:
connect-gzip
.There are multiple Gzip middlewares for Express, KOA and others. For example: https://www.npmjs.com/package/express-static-gzip
However, Node is awfully bad at doing CPU intensive tasks like gzipping, SSL termination, etc. Instead, use a ‘real’ middleware services like nginx or HAproxy, see bullet 3 here: http://goldbergyoni.com/checklist-best-practice-of-node-js-in-production/
It's been a few good days with node, and you're right to say that you can't create a webserver without gzip.
There are quite a lot options given on the modules page on the Node.js Wiki. I tried out most of them, but this is the one which I'm finally using -
https://github.com/donnerjack13589/node.gzip
v1.0 is also out and it has been quite stable so far.
Use gzip compression
Gzip compressing can greatly decrease the size of the response body and hence increase the speed of a web app. Use the compression middleware for gzip compression in your Express app. For example:
Even if you're not using express, you can still use their middleware. The compression module is what I'm using: